LCOV - code coverage report
Current view: top level - svtools/source/dialogs - mcvmath.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 16 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 9 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 INCLUDED_SVTOOLS_SOURCE_DIALOGS_MCVMATH_HXX
      21             : #define INCLUDED_SVTOOLS_SOURCE_DIALOGS_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             :     enum class Bits { Bits };
      79             : 
      80           0 :     Fix(long bits, Bits): x(bits) {}
      81             : 
      82             :     void            SetInternVal( long nVal ) { x=nVal; }
      83             :     long            GetInternVal() const { return x; }
      84             : 
      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 );
      90             : 
      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; }
      95             : 
      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; }
      98             : 
      99             :     operator        long() const    { return (x+FIX_ADD) >> FIX_POST; }
     100             :     operator        double() const  { return double(x)/(1<<FIX_POST); }
     101             : 
     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 );
     106             : 
     107             :     friend FixCpx   operator-( const FixCpx& a );
     108             : };
     109             : 
     110             : 
     111             : // - FixCpx -
     112             : 
     113             : 
     114             : class FixCpx
     115             : {
     116             : public:
     117             :     Fix             r;
     118             :     Fix             i;
     119             : 
     120             : public:
     121           0 :                     FixCpx()               : r(), i() {}
     122           0 :                     FixCpx( Fix a )        : r( a ), i() {}
     123             :                     FixCpx( Fix a, Fix b ) : r( a ), i( b ) {}
     124             : 
     125             :     Fix&            GetReal() { return r; }
     126             :     Fix&            GetImag() { return i; }
     127             : 
     128             :     void            operator*= ( const FixCpx& ra );
     129             :     void            MultBig( const FixCpx& ra, const FixCpx& rb );
     130             : 
     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 );
     136             : };
     137             : 
     138             : inline Fix operator- ( const Fix& a )
     139             : {
     140             :     Fix f;
     141             :     f.x = -a.x;
     142             :     return f;
     143             : }
     144             : 
     145           0 : inline Fix operator+ ( const Fix& a, const Fix& b )
     146             : {
     147           0 :     return Fix(a.x+b.x, Fix::Bits::Bits);
     148             : }
     149             : 
     150           0 : inline Fix operator- ( const Fix& a, const Fix& b )
     151             : {
     152           0 :     return Fix(a.x-b.x, Fix::Bits::Bits);
     153             : }
     154             : 
     155           0 : inline Fix operator* ( const Fix& a, const Fix& b )
     156             : {
     157           0 :     return Fix((a.x*b.x+FIX_ADD)>>FIX_POST, Fix::Bits::Bits);
     158             : }
     159             : 
     160             : inline Fix operator/ ( const Fix& a, const Fix& b )
     161             : {
     162             :     return Fix((a.x<<FIX_POST)/b.x, Fix::Bits::Bits);
     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 // INCLUDED_SVTOOLS_SOURCE_DIALOGS_MCVMATH_HXX
     210             : 
     211             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11