connectivity/source/drivers/file/FNumericFunctions.cxx             |    9 ++---
 odk/examples/DevelopersGuide/ProfUNO/CppBinding/string_samples.cxx |    7 +--
 scaddins/source/analysis/bessel.cxx                                |   18 
+++-------
 slideshow/source/engine/opengl/TransitionImpl.cxx                  |    6 +--
 starmath/source/node.cxx                                           |    5 +-
 vcl/source/filter/imet/ios2met.cxx                                 |    9 ++---
 6 files changed, 23 insertions(+), 31 deletions(-)

New commits:
commit 5f21eaa0e6b689233336cacc949b9a55d545088f
Author:     pragat-pandya <pragat.pan...@gmail.com>
AuthorDate: Tue Feb 1 05:59:42 2022 +0530
Commit:     Hossein <hoss...@libreoffice.org>
CommitDate: Tue Feb 15 12:17:50 2022 +0100

    tdf#145759 Using M_PI from cmath instead of magic constants.
    
    Replace the instances of Pi's value as magic number by M_PI
    Use M_PI_2 and 2_M_PI instead of calculating these values in code.
    Use basegfx functions to convert angle units.
    
    Change-Id: I6cca7cc93704a70ccf3a0571a56a789bc9df51ef
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129479
    Reviewed-by: Arkadiy Illarionov <qar...@gmail.com>
    Reviewed-by: Hossein <hoss...@libreoffice.org>
    Tested-by: Jenkins

diff --git a/connectivity/source/drivers/file/FNumericFunctions.cxx 
b/connectivity/source/drivers/file/FNumericFunctions.cxx
index 7de058dee06c..7c7fdc75425f 100644
--- a/connectivity/source/drivers/file/FNumericFunctions.cxx
+++ b/connectivity/source/drivers/file/FNumericFunctions.cxx
@@ -19,14 +19,13 @@
 
 
 #include <cmath>
+#include <basegfx/numeric/ftools.hxx>
 #include <file/FNumericFunctions.hxx>
 #include <rtl/math.hxx>
 
 using namespace connectivity;
 using namespace connectivity::file;
 
-const double fPi = 3.14159265358979323846;
-
 ORowSetValue OOp_Abs::operate(const ORowSetValue& lhs) const
 {
     if ( lhs.isNull() )
@@ -162,7 +161,7 @@ ORowSetValue OOp_Sqrt::operate(const ORowSetValue& lhs) 
const
 
 ORowSetValue OOp_Pi::operate(const std::vector<ORowSetValue>& /*lhs*/) const
 {
-    return fPi;
+    return M_PI;
 }
 
 ORowSetValue OOp_Cos::operate(const ORowSetValue& lhs) const
@@ -227,7 +226,7 @@ ORowSetValue OOp_Degrees::operate(const ORowSetValue& lhs) 
const
         return lhs;
 
     double nLhs = lhs.getDouble();
-    return nLhs*180*(1.0/fPi);
+    return basegfx::rad2deg(nLhs);
 }
 
 ORowSetValue OOp_Radians::operate(const ORowSetValue& lhs) const
@@ -236,7 +235,7 @@ ORowSetValue OOp_Radians::operate(const ORowSetValue& lhs) 
const
         return lhs;
 
     double nLhs = lhs.getDouble();
-    return nLhs*fPi*(1.0/180.0);
+    return basegfx::deg2rad(nLhs);
 }
 
 
diff --git a/odk/examples/DevelopersGuide/ProfUNO/CppBinding/string_samples.cxx 
b/odk/examples/DevelopersGuide/ProfUNO/CppBinding/string_samples.cxx
index 26162eeb3617..f8bb34f97cd4 100644
--- a/odk/examples/DevelopersGuide/ProfUNO/CppBinding/string_samples.cxx
+++ b/odk/examples/DevelopersGuide/ProfUNO/CppBinding/string_samples.cxx
@@ -34,7 +34,7 @@
  *************************************************************************/
 
 #include <stdio.h>
-
+#include <cmath>
 #include <sal/main.h>
 
 #include <rtl/ustrbuf.hxx>
@@ -49,7 +49,6 @@ SAL_IMPLEMENT_MAIN()
     // string concatenation
 
     sal_Int32 n = 42;
-    double pi = 3.14159;
 
     // give it an initial size, should be a good guess.
     // stringbuffer extends if necessary
@@ -59,7 +58,7 @@ SAL_IMPLEMENT_MAIN()
     buf.append("pi ( here ");
 
     // numbers can be simply appended
-    buf.append(pi);
+    buf.append(M_PI);
 
     // lets the compiler count the stringlength, so this is more efficient than
     // the above appendAscii call, where length of the string must be 
calculated at
@@ -67,7 +66,7 @@ SAL_IMPLEMENT_MAIN()
     buf.append(" ) multiplied with ");
     buf.append(n);
     buf.append(" gives ");
-    buf.append((double)(n * pi));
+    buf.append((double)(n * M_PI));
     buf.append(".");
 
     // now transfer the buffer into the string.
diff --git a/scaddins/source/analysis/bessel.cxx 
b/scaddins/source/analysis/bessel.cxx
index 623415e18dfe..44b79e798f85 100644
--- a/scaddins/source/analysis/bessel.cxx
+++ b/scaddins/source/analysis/bessel.cxx
@@ -18,7 +18,7 @@
  */
 
 #include "bessel.hxx"
-
+#include <cmath>
 #include <rtl/math.hxx>
 
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
@@ -29,12 +29,6 @@ using ::com::sun::star::sheet::NoConvergenceException;
 
 namespace sca::analysis {
 
-const double f_PI       = 3.1415926535897932385;
-const double f_PI_DIV_2 = f_PI / 2.0;
-const double f_PI_DIV_4 = f_PI / 4.0;
-const double f_2_DIV_PI = 2.0 / f_PI;
-
-
 // BESSEL J
 
 
@@ -77,7 +71,7 @@ double BesselJ( double x, sal_Int32 N )
     {
         if (!bAsymptoticPossible)
             throw NoConvergenceException();
-        return fSign * sqrt(f_2_DIV_PI/fX)* cos(fX-N*f_PI_DIV_2-f_PI_DIV_4);
+        return fSign * sqrt(M_2_PI/fX)* cos(fX-N*M_PI_2-M_PI_4);
     }
 
     double const epsilon = 1.0e-15; // relative error
@@ -330,7 +324,7 @@ static double Bessely0( double fX )
         throw IllegalArgumentException();
     const double fMaxIteration = 9000000.0; // should not be reached
     if (fX > 5.0e+6) // iteration is not considerable better then approximation
-        return sqrt(1/f_PI/fX)
+        return sqrt(1/M_PI/fX)
                 *(std::sin(fX)-std::cos(fX));
     const double epsilon = 1.0e-15;
     const double EulerGamma = 0.57721566490153286060;
@@ -370,7 +364,7 @@ static double Bessely0( double fX )
     while (!bHasFound && k<fMaxIteration);
     if (!bHasFound)
         throw NoConvergenceException(); // not likely to happen
-    return u*f_2_DIV_PI;
+    return u*M_2_PI;
 }
 
 // See #i31656# for a commented version of this implementation, attachment 
#desc6
@@ -384,7 +378,7 @@ static double Bessely1( double fX )
         throw IllegalArgumentException();
     const double fMaxIteration = 9000000.0; // should not be reached
     if (fX > 5.0e+6) // iteration is not considerable better then approximation
-        return - sqrt(1/f_PI/fX)
+        return - sqrt(1/M_PI/fX)
                 *(std::sin(fX)+std::cos(fX));
     const double epsilon = 1.0e-15;
     const double EulerGamma = 0.57721566490153286060;
@@ -426,7 +420,7 @@ static double Bessely1( double fX )
     while (!bHasFound && k<fMaxIteration);
     if (!bHasFound)
         throw NoConvergenceException();
-    return -u*2.0/f_PI;
+    return -u*2.0/M_PI;
 }
 
 double BesselY( double fNum, sal_Int32 nOrder )
diff --git a/slideshow/source/engine/opengl/TransitionImpl.cxx 
b/slideshow/source/engine/opengl/TransitionImpl.cxx
index ee0089cbae9e..ba43acddc38c 100644
--- a/slideshow/source/engine/opengl/TransitionImpl.cxx
+++ b/slideshow/source/engine/opengl/TransitionImpl.cxx
@@ -39,7 +39,7 @@
 
 #include "Operation.hxx"
 #include "TransitionImpl.hxx"
-#include <math.h>
+#include <cmath>
 
 TransitionScene::TransitionScene(TransitionScene const& rOther)
     : maLeavingSlidePrimitives(rOther.maLeavingSlidePrimitives)
@@ -946,7 +946,7 @@ static T clamp(const T& rIn)
 
 std::shared_ptr<OGLTransitionImpl> makeRevolvingCircles( sal_uInt16 nCircles , 
sal_uInt16 nPointsOnCircles )
 {
-    double dAngle(2*3.1415926/static_cast<double>( nPointsOnCircles ));
+    double dAngle(2*M_PI/static_cast<double>( nPointsOnCircles ));
     if(nCircles < 2 || nPointsOnCircles < 4)
         return makeNByMTileFlip(1,1);
     float Radius(1.0/static_cast<double>( nCircles ));
@@ -963,7 +963,7 @@ std::shared_ptr<OGLTransitionImpl> makeRevolvingCircles( 
sal_uInt16 nCircles , s
     float TempAngle(0.0);
     for(unsigned int Point(0); Point < nPointsOnCircles; ++Point)
     {
-        unScaledTexCoords.emplace_back( cos(TempAngle - 3.1415926/2.0) , 
sin(TempAngle- 3.1415926/2.0) );
+        unScaledTexCoords.emplace_back( cos(TempAngle - M_PI_2) , 
sin(TempAngle- M_PI_2) );
 
         TempAngle += dAngle;
     }
diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx
index 5306908cefbe..a13f5deada56 100644
--- a/starmath/source/node.cxx
+++ b/starmath/source/node.cxx
@@ -22,9 +22,9 @@
 #include <smmod.hxx>
 #include "tmpdevice.hxx"
 #include <visitors.hxx>
-
 #include <vcl/metric.hxx>
 #include <osl/diagnose.h>
+#include <basegfx/numeric/ftools.hxx>
 
 namespace {
 
@@ -988,8 +988,7 @@ void SmBinDiagonalNode::GetOperPosSize(Point &rPos, Size 
&rSize,
                         const Point &rDiagPoint, double fAngleDeg) const
 
 {
-    static const double  fPi   = 3.1415926535897932384626433;
-    double  fAngleRad   = fAngleDeg / 180.0 * fPi;
+    double  fAngleRad   = basegfx::deg2rad(fAngleDeg);
     tools::Long    nRectLeft   = GetItalicLeft(),
             nRectRight  = GetItalicRight(),
             nRectTop    = GetTop(),
diff --git a/vcl/source/filter/imet/ios2met.cxx 
b/vcl/source/filter/imet/ios2met.cxx
index 992a6c5d5e60..2beac50bde2c 100644
--- a/vcl/source/filter/imet/ios2met.cxx
+++ b/vcl/source/filter/imet/ios2met.cxx
@@ -29,8 +29,9 @@
 #include <vcl/lineinfo.hxx>
 #include <vcl/gdimtf.hxx>
 #include <filter/MetReader.hxx>
+#include <basegfx/numeric/ftools.hxx>
 
-#include <math.h>
+#include <cmath>
 #include <memory>
 
 class FilterConfigItem;
@@ -1222,8 +1223,8 @@ void OS2METReader::ReadPartialArc(bool bGivenPos, 
sal_uInt16 nOrderSize)
 
     sal_Int32 nStart(0), nSweep(0);
     pOS2MET->ReadInt32( nStart ).ReadInt32( nSweep );
-    double fStart = static_cast<double>(nStart)/65536.0/180.0*3.14159265359;
-    double fEnd = fStart+ 
static_cast<double>(nSweep)/65536.0/180.0*3.14159265359;
+    double fStart = basegfx::deg2rad<65536>(static_cast<double>(nStart));
+    double fEnd = fStart+ basegfx::deg2rad<65536>(static_cast<double>(nSweep));
     aPStart=Point(aCenter.X()+static_cast<sal_Int32>( cos(fStart)*nP),
                   aCenter.Y()+static_cast<sal_Int32>(-sin(fStart)*nQ));
     aPEnd=  Point(aCenter.X()+static_cast<sal_Int32>( cos(fEnd)*nP),
@@ -2071,7 +2072,7 @@ void OS2METReader::ReadOrder(sal_uInt16 nOrderID, 
sal_uInt16 nOrderLen)
             sal_Int32 nY = ReadCoord(bCoord32);
             if (nX>=0 && nY==0) aAttr.nChrAng=0_deg10;
             else {
-                aAttr.nChrAng = 
Degree10(static_cast<short>(atan2(static_cast<double>(nY),static_cast<double>(nX))/3.1415926539*1800.0));
+                aAttr.nChrAng = 
Degree10(static_cast<short>(basegfx::rad2deg<10>(atan2(static_cast<double>(nY),static_cast<double>(nX)))));
                 while (aAttr.nChrAng < 0_deg10) aAttr.nChrAng += 3600_deg10;
                 aAttr.nChrAng %= 3600_deg10;
             }

Reply via email to