1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVTOOLS_SOURCE_DIALOGS_MCVMATH_HXX
21 #define INCLUDED_SVTOOLS_SOURCE_DIALOGS_MCVMATH_HXX
23 #include <tools/solar.h>
28 // allowed range 0..14, must be even
31 // scale for ...Big() -Functions
34 #define FIX_P3 (FIX_POST-FIX_P2)
37 #define FIX_P3 FIX_POST
41 #define FIX_ADD (1<<(FIX_POST-1))
47 #define FIX_A2 (1<<(FIX_P2-1))
53 #define FIX_A3 (1<<(FIX_P3-1))
72 Fix( int i
) { x
=(long(i
)<<FIX_POST
); }
73 Fix( short l
) { x
=(long(l
)<<FIX_POST
); }
74 Fix( sal_uInt16 l
) { x
=(long(l
)<<FIX_POST
); }
75 Fix( long l
) { x
=(l
<<FIX_POST
); }
76 Fix( long Z
, long N
) { x
=(Z
<<FIX_POST
)/N
; }
78 enum class Bits
{ Bits
};
80 Fix(long bits
, Bits
): x(bits
) {}
82 void SetInternVal( long nVal
) { x
=nVal
; }
83 long GetInternVal() const { return x
; }
85 void operator+= ( const Fix
& a
) { x
+=a
.x
; }
86 void operator-= ( const Fix
& a
) { x
-=a
.x
; }
87 void operator*= ( const Fix
& a
) { x
=(x
*a
.x
+FIX_ADD
)>>FIX_POST
; }
88 void operator/= ( const Fix
& a
) { x
=(x
<<FIX_POST
)/a
.x
; }
89 friend Fix
operator- ( const Fix
& a
);
91 void MultBig( const Fix
& a
)
92 { x
=((((a
.x
+FIX_A2
)>>FIX_P2
)*x
+FIX_A3
)>>FIX_P3
); }
93 void DivBig( const Fix
& a
)
94 { x
=((x
<<FIX_P3
)/a
.x
)<<FIX_P2
; }
96 friend bool operator> ( const Fix
& a
, const Fix
& b
) { return a
.x
> b
.x
; }
97 friend bool operator< ( const Fix
& a
, const Fix
& b
) { return a
.x
< b
.x
; }
99 operator long() const { return (x
+FIX_ADD
) >> FIX_POST
; }
100 operator double() const { return double(x
)/(1<<FIX_POST
); }
102 friend Fix
operator+ ( const Fix
& a
, const Fix
& b
);
103 friend Fix
operator- ( const Fix
& a
, const Fix
& b
);
104 friend Fix
operator* ( const Fix
& a
, const Fix
& b
);
105 friend Fix
operator/ ( const Fix
& a
, const Fix
& b
);
107 friend FixCpx
operator-( const FixCpx
& a
);
121 FixCpx() : r(), i() {}
122 FixCpx( Fix a
) : r( a
), i() {}
123 FixCpx( Fix a
, Fix b
) : r( a
), i( b
) {}
125 Fix
& GetReal() { return r
; }
126 Fix
& GetImag() { return i
; }
128 void operator*= ( const FixCpx
& ra
);
129 void MultBig( const FixCpx
& ra
, const FixCpx
& rb
);
131 friend FixCpx
operator+ ( const FixCpx
& a
, const FixCpx
& b
);
132 friend FixCpx
operator- ( const FixCpx
& a
, const FixCpx
& b
);
133 friend FixCpx
operator* ( const FixCpx
& a
, const FixCpx
& b
);
134 friend FixCpx
operator/ ( const FixCpx
& a
, const FixCpx
& b
);
135 friend FixCpx
operator- ( const FixCpx
& a
);
138 inline Fix
operator- ( const Fix
& a
)
145 inline Fix
operator+ ( const Fix
& a
, const Fix
& b
)
147 return Fix(a
.x
+b
.x
, Fix::Bits::Bits
);
150 inline Fix
operator- ( const Fix
& a
, const Fix
& b
)
152 return Fix(a
.x
-b
.x
, Fix::Bits::Bits
);
155 inline Fix
operator* ( const Fix
& a
, const Fix
& b
)
157 return Fix((a
.x
*b
.x
+FIX_ADD
)>>FIX_POST
, Fix::Bits::Bits
);
160 inline Fix
operator/ ( const Fix
& a
, const Fix
& b
)
162 return Fix((a
.x
<<FIX_POST
)/b
.x
, Fix::Bits::Bits
);
165 inline FixCpx
operator- ( const FixCpx
& a
)
174 inline FixCpx
operator+ ( const FixCpx
& a
, const FixCpx
& b
)
176 return FixCpx( a
.r
+b
.r
, a
.i
+b
.i
);
179 inline FixCpx
operator- ( const FixCpx
& a
, const FixCpx
& b
)
181 return FixCpx( a
.r
-b
.r
, a
.i
-b
.i
);
184 inline void FixCpx::operator*= ( const FixCpx
& ra
)
186 Fix rr
= ra
.r
*r
-ra
.i
*i
;
191 inline FixCpx
operator* ( const FixCpx
& a
, const FixCpx
& b
)
193 return FixCpx( a
.r
*b
.r
-a
.i
*b
.i
, a
.r
*b
.i
+a
.i
*b
.r
);
196 inline FixCpx
operator/ ( const FixCpx
& a
, const FixCpx
& b
)
198 return FixCpx( (a
.r
*b
.r
+a
.i
*b
.i
)/(b
.r
*b
.r
+b
.i
*b
.i
),
199 (b
.r
*a
.r
-a
.r
*b
.i
)/(b
.r
*b
.r
+b
.i
*b
.i
) );
204 Fix
ImpMultBig2( const Fix
& a
, const Fix
& b
);
206 sal_uInt16
ImpSqrt( sal_uLong nRadi
);
207 FixCpx
ImpExPI( sal_uInt16 nPhi
);
209 #endif // INCLUDED_SVTOOLS_SOURCE_DIALOGS_MCVMATH_HXX
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */