Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <mcvmath.hxx>
31 : :
32 : : // ---------------------------------------------------------------------
33 : : // die folgenden Tabellen enthalten sin(phi) * 2**14
34 : : // fuer phi= 360Grad*2**-32 bis 360 Grad
35 : : // def. fuer x: phi=360Grad * 2**(x-16)
36 : : // d.h. x = 16 -> 360 Grad
37 : : // x = -16 -> (2**-16) * 360 Grad
38 : : // x: -16 ... 0 ... 15
39 : : //x= 0, 1, 2, 3, 4, 5, 6, 7,
40 : : // 8, 9, 10, 11, 12, 13, 14, 15
41 : :
42 : : static const short CosTab[16] =
43 : : {
44 : : 16384, 16384, 16384, 16384, 16384, 16384, 16384, 16383,
45 : : 16379, 16364, 16305, 16069, 15137, 11585, 0, -16383
46 : : };
47 : : static const short SinTab[16]=
48 : : {
49 : : 2, 3, 6, 13, 25, 50, 101, 201,
50 : : 402, 804, 1606, 3196, 6270, 11585, 16384, 0
51 : : };
52 : :
53 : : /**************************************************************************
54 : : |*
55 : : |* ImpMultBig2()
56 : : |*
57 : : |* Beschreibung Multiplikation fuer FixPoint-Berechnungen
58 : : |*
59 : : **************************************************************************/
60 : :
61 : : // first parameter should be the bigger one
62 : :
63 : 0 : Fix ImpMultBig2( const Fix& a, const Fix& b )
64 : : {
65 : 0 : Fix f;
66 : 0 : f.x = (((b.x+FIX_A2)>>FIX_P2)*a.x+FIX_A3)>>FIX_P3;
67 : 0 : return f;
68 : : }
69 : :
70 : : /**************************************************************************
71 : : |*
72 : : |* ImpSqrt()
73 : : |*
74 : : |* Beschreibung Wurzelfunktion fuer FixPoint-Berechnungen
75 : : |*
76 : : **************************************************************************/
77 : :
78 : 0 : sal_uInt16 ImpSqrt( sal_uLong nRadi )
79 : : {
80 : 0 : register sal_uLong inf = 1;
81 : 0 : register sal_uLong sup = nRadi;
82 : : register sal_uLong sqr;
83 : :
84 [ # # ]: 0 : if ( !nRadi )
85 : 0 : return 0;
86 : :
87 [ # # ]: 0 : while ( (inf<<1) <= sup )
88 : : {
89 : 0 : sup >>= 1;
90 : 0 : inf <<= 1;
91 : : }
92 : 0 : sqr = (sup+inf) >> 1; // Anfangswert der Iteration
93 : :
94 : 0 : sqr = (nRadi/sqr + sqr) >> 1; // 2 Newton-Iterationen reichen fuer
95 : 0 : sqr = (nRadi/sqr + sqr) >> 1; // +- 1 Digit
96 : :
97 : 0 : return sal::static_int_cast< sal_uInt16 >(sqr);
98 : : }
99 : :
100 : : /**************************************************************************
101 : : |*
102 : : |* ImpExPI()
103 : : |*
104 : : |* Beschreibung EXPI-Funktion fuer FixPoint-Berechnungen
105 : : |*
106 : : **************************************************************************/
107 : :
108 : : // e**(i*nPhi), Einheit nPhi: 2**16 == 360 Grad
109 : :
110 : 0 : FixCpx ImpExPI( sal_uInt16 nPhi )
111 : : {
112 : : short i;
113 : 0 : FixCpx aIter(1L); // e**(0*i)
114 : 0 : FixCpx Mul;
115 : 0 : const char Sft=14-FIX_POST;
116 : :
117 [ # # ]: 0 : for ( i = 15; i >= 0; i-- )
118 : : {
119 [ # # ]: 0 : if ( (1L<<i) & nPhi )
120 : : {
121 : 0 : Mul.r.x = CosTab[i]>>Sft; // e**(i(phi1+phi2)) =
122 : 0 : Mul.i.x = SinTab[i]>>Sft; // e**(i*phi1)) * e**(i*phi2))
123 : 0 : aIter *= Mul;
124 : : }
125 : : }
126 : :
127 : 0 : return aIter;
128 : : }
129 : :
130 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|