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 .
21 #include <mcvmath.hxx>
23 // ---------------------------------------------------------------------
24 // die folgenden Tabellen enthalten sin(phi) * 2**14
25 // fuer phi= 360Grad*2**-32 bis 360 Grad
26 // def. fuer x: phi=360Grad * 2**(x-16)
27 // d.h. x = 16 -> 360 Grad
28 // x = -16 -> (2**-16) * 360 Grad
29 // x: -16 ... 0 ... 15
30 //x= 0, 1, 2, 3, 4, 5, 6, 7,
31 // 8, 9, 10, 11, 12, 13, 14, 15
33 static const short CosTab
[16] =
35 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16383,
36 16379, 16364, 16305, 16069, 15137, 11585, 0, -16383
38 static const short SinTab
[16]=
40 2, 3, 6, 13, 25, 50, 101, 201,
41 402, 804, 1606, 3196, 6270, 11585, 16384, 0
44 /**************************************************************************
48 |* Beschreibung Multiplikation fuer FixPoint-Berechnungen
50 **************************************************************************/
52 // first parameter should be the bigger one
54 Fix
ImpMultBig2( const Fix
& a
, const Fix
& b
)
57 f
.x
= (((b
.x
+FIX_A2
)>>FIX_P2
)*a
.x
+FIX_A3
)>>FIX_P3
;
61 /**************************************************************************
65 |* Beschreibung Wurzelfunktion fuer FixPoint-Berechnungen
67 **************************************************************************/
69 sal_uInt16
ImpSqrt( sal_uLong nRadi
)
72 sal_uLong sup
= nRadi
;
78 while ( (inf
<<1) <= sup
)
83 sqr
= (sup
+inf
) >> 1; // Anfangswert der Iteration
85 sqr
= (nRadi
/sqr
+ sqr
) >> 1; // 2 Newton-Iterationen reichen fuer
86 sqr
= (nRadi
/sqr
+ sqr
) >> 1; // +- 1 Digit
88 return sal::static_int_cast
< sal_uInt16
>(sqr
);
91 /**************************************************************************
95 |* Beschreibung EXPI-Funktion fuer FixPoint-Berechnungen
97 **************************************************************************/
99 // e**(i*nPhi), Einheit nPhi: 2**16 == 360 Grad
101 FixCpx
ImpExPI( sal_uInt16 nPhi
)
104 FixCpx
aIter(1L); // e**(0*i)
106 const char Sft
=14-FIX_POST
;
108 for ( i
= 15; i
>= 0; i
-- )
110 if ( (1L<<i
) & nPhi
)
112 Mul
.r
.x
= CosTab
[i
]>>Sft
; // e**(i(phi1+phi2)) =
113 Mul
.i
.x
= SinTab
[i
]>>Sft
; // e**(i*phi1)) * e**(i*phi2))
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */