LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/dialogs - mcvmath.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 18 0.0 %
Date: 2012-12-27 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef _MCVMATH_HXX
      21             : #define _MCVMATH_HXX
      22             : 
      23             : #include <tools/solar.h>
      24             : 
      25             : class FixCpx;
      26             : 
      27             : // No of fractal bits
      28             : // allowed range 0..14, must be even
      29             : #define FIX_POST 14
      30             : 
      31             : // scale for ...Big() -Functions
      32             : #if (FIX_POST>=4)
      33             : #define FIX_P2  4
      34             : #define FIX_P3  (FIX_POST-FIX_P2)
      35             : #else
      36             : #define FIX_P2  0
      37             : #define FIX_P3  FIX_POST
      38             : #endif
      39             : 
      40             : #if (FIX_POST>=1)
      41             : #define FIX_ADD (1<<(FIX_POST-1))
      42             : #else
      43             : #define FIX_ADD 0
      44             : #endif
      45             : 
      46             : #if (FIX_P2>=1)
      47             : #define FIX_A2 (1<<(FIX_P2-1))
      48             : #else
      49             : #define FIX_A2 0
      50             : #endif
      51             : 
      52             : #if (FIX_P3>=1)
      53             : #define FIX_A3 (1<<(FIX_P3-1))
      54             : #else
      55             : #define FIX_A3 0
      56             : #endif
      57             : 
      58             : // -------
      59             : // - Fix -
      60             : // -------
      61             : 
      62             : class Fix
      63             : {
      64             : private:
      65             :     friend  class FixCpx;
      66             : 
      67             : public:
      68             :     long            x;
      69             : 
      70             : public:
      71           0 :                     Fix() { x=0; }
      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           0 :                     Fix( long l ) { x=(l<<FIX_POST); }
      76             :                     Fix( long Z, long N ) { x=(Z<<FIX_POST)/N; }
      77             : 
      78             :     void            SetInternVal( long nVal ) { x=nVal; }
      79             :     long            GetInternVal() const { return x; }
      80             : 
      81             :     void            operator+= ( const Fix& a ) { x+=a.x; }
      82             :     void            operator-= ( const Fix& a ) { x-=a.x; }
      83             :     void            operator*= ( const Fix& a ) { x=(x*a.x+FIX_ADD)>>FIX_POST; }
      84             :     void            operator/= ( const Fix& a ) { x=(x<<FIX_POST)/a.x; }
      85             :     friend Fix      operator-  ( const Fix& a );
      86             : 
      87             :     void            MultBig( const Fix& a )
      88             :                         { x=((((a.x+FIX_A2)>>FIX_P2)*x+FIX_A3)>>FIX_P3); }
      89             :     void            DivBig( const Fix& a )
      90             :                         { x=((x<<FIX_P3)/a.x)<<FIX_P2; }
      91             : 
      92             :     friend sal_Bool     operator> ( const Fix& a, const Fix& b ) { return a.x > b.x; }
      93             :     friend sal_Bool     operator< ( const Fix& a, const Fix& b ) { return a.x < b.x; }
      94             : 
      95             :     operator        long() const    { return (x+FIX_ADD) >> FIX_POST; }
      96             :     operator        double() const  { return double(x)/(1<<FIX_POST); }
      97             : 
      98             :     friend Fix      operator+ ( const Fix& a, const Fix& b );
      99             :     friend Fix      operator- ( const Fix& a, const Fix& b );
     100             :     friend Fix      operator* ( const Fix& a, const Fix& b );
     101             :     friend Fix      operator/ ( const Fix& a, const Fix& b );
     102             : 
     103             :     friend FixCpx   operator-( const FixCpx& a );
     104             : };
     105             : 
     106             : // ----------
     107             : // - FixCpx -
     108             : // ----------
     109             : 
     110             : class FixCpx
     111             : {
     112             : public:
     113             :     Fix             r;
     114             :     Fix             i;
     115             : 
     116             : public:
     117           0 :                     FixCpx()               : r(), i() {}
     118           0 :                     FixCpx( Fix a )        : r( a ), i() {}
     119             :                     FixCpx( Fix a, Fix b ) : r( a ), i( b ) {}
     120             : 
     121             :     Fix&            GetReal() { return r; }
     122             :     Fix&            GetImag() { return i; }
     123             : 
     124             :     void            operator*= ( const FixCpx& ra );
     125             :     void            MultBig( const FixCpx& ra, const FixCpx& rb );
     126             : 
     127             :     friend FixCpx   operator+ ( const FixCpx& a, const FixCpx& b );
     128             :     friend FixCpx   operator- ( const FixCpx& a, const FixCpx& b );
     129             :     friend FixCpx   operator* ( const FixCpx& a, const FixCpx& b );
     130             :     friend FixCpx   operator/ ( const FixCpx& a, const FixCpx& b );
     131             :     friend FixCpx   operator- ( const FixCpx& a );
     132             : };
     133             : 
     134             : inline Fix operator- ( const Fix& a )
     135             : {
     136             :     Fix f;
     137             :     f.x = -a.x;
     138             :     return f;
     139             : }
     140             : 
     141           0 : inline Fix operator+ ( const Fix& a, const Fix& b )
     142             : {
     143           0 :     long l = a.x+b.x;
     144           0 :     return *((Fix*)&l);
     145             : }
     146             : 
     147           0 : inline Fix operator- ( const Fix& a, const Fix& b )
     148             : {
     149           0 :     long l = a.x-b.x;
     150           0 :     return *((Fix*)&l);
     151             : }
     152             : 
     153           0 : inline Fix operator* ( const Fix& a, const Fix& b )
     154             : {
     155           0 :     long l=(a.x*b.x+FIX_ADD)>>FIX_POST;
     156           0 :     return *((Fix*)&l);
     157             : }
     158             : 
     159             : inline Fix operator/ ( const Fix& a, const Fix& b )
     160             : {
     161             :     long l=(a.x<<FIX_POST)/b.x;
     162             :     return *((Fix*)&l);
     163             : }
     164             : 
     165             : inline FixCpx operator- ( const FixCpx& a )
     166             : {
     167             :     FixCpx fc;
     168             : 
     169             :     fc.r.x = -a.r.x;
     170             :     fc.i.x = -a.i.x;
     171             :     return fc;
     172             : }
     173             : 
     174             : inline FixCpx operator+ ( const FixCpx& a, const FixCpx& b )
     175             : {
     176             :     return FixCpx( a.r+b.r, a.i+b.i );
     177             : }
     178             : 
     179             : inline FixCpx operator- ( const FixCpx& a, const FixCpx& b )
     180             : {
     181             :     return FixCpx( a.r-b.r, a.i-b.i );
     182             : }
     183             : 
     184           0 : inline void FixCpx::operator*= ( const FixCpx& ra )
     185             : {
     186           0 :     Fix rr = ra.r*r-ra.i*i;
     187           0 :     i = ra.r*i+ra.i*r;
     188           0 :     r = rr;
     189           0 : }
     190             : 
     191             : inline FixCpx operator* ( const FixCpx& a, const FixCpx& b )
     192             : {
     193             :     return FixCpx( a.r*b.r-a.i*b.i, a.r*b.i+a.i*b.r );
     194             : }
     195             : 
     196             : inline FixCpx operator/ ( const FixCpx& a, const FixCpx& b )
     197             : {
     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) );
     200             : }
     201             : 
     202             : // -----------------------------------------------------------------------
     203             : 
     204             : Fix ImpMultBig2( const Fix& a, const Fix& b );
     205             : 
     206             : sal_uInt16 ImpSqrt( sal_uLong nRadi );
     207             : FixCpx ImpExPI( sal_uInt16 nPhi );
     208             : 
     209             : #endif // _MCVMATH_HXX
     210             : 
     211             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10