chart2/source/view/main/ShapeFactory.cxx    |    3 ++-
 sc/source/core/tool/interpr3.cxx            |    2 +-
 scaddins/source/analysis/analysishelper.cxx |    8 +++++---
 scaddins/source/pricing/black_scholes.cxx   |    2 +-
 stoc/test/testconv.cxx                      |    5 +++--
 5 files changed, 12 insertions(+), 8 deletions(-)

New commits:
commit 4cec1ec1d575ff0328f014de57abb591e3c7ae11
Author:     OmkarAcharekar <[email protected]>
AuthorDate: Sat Oct 22 01:47:10 2022 +0530
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Tue Oct 25 08:12:26 2022 +0200

    tdf#145759 Use symbolic constants instead of magic numerical constants
    
    Change-Id: I68f9dd0bbe5a98de35253220dc33382139b4950e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141657
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <[email protected]>

diff --git a/chart2/source/view/main/ShapeFactory.cxx 
b/chart2/source/view/main/ShapeFactory.cxx
index 29259bb7100c..f9efceb676a5 100644
--- a/chart2/source/view/main/ShapeFactory.cxx
+++ b/chart2/source/view/main/ShapeFactory.cxx
@@ -58,6 +58,7 @@
 #include <sal/log.hxx>
 
 #include <algorithm>
+#include <cmath>
 #include <cstddef>
 
 using namespace ::com::sun::star;
@@ -1322,7 +1323,7 @@ static drawing::PointSequenceSequence 
createPolyPolygon_Symbol( const drawing::P
         }
         case Symbol_Circle:
         {
-            double fOmega = 1.5707963267948966192 / (nQuarterCount + 1.0);
+            double fOmega = M_PI_2 / (nQuarterCount + 1.0);
             // one point in the middle of each edge to get full size bounding 
rectangle
             *pInnerSequence++ = toPoint( fX + fWidthH, fY );
             // 0 to PI/2
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 46de733e398f..962f61970ee6 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -199,7 +199,7 @@ double ScInterpreter::phi(double x)
 
 double ScInterpreter::integralPhi(double x)
 { // Using gauss(x)+0.5 has severe cancellation errors for x<-4
-    return 0.5 * std::erfc(-x * 0.7071067811865475); // * 1/sqrt(2)
+    return 0.5 * std::erfc(-x * M_SQRT1_2);
 }
 
 double ScInterpreter::taylor(const double* pPolynom, sal_uInt16 nMax, double x)
diff --git a/scaddins/source/analysis/analysishelper.cxx 
b/scaddins/source/analysis/analysishelper.cxx
index 58f5a4087543..11f5c3abe9dd 100644
--- a/scaddins/source/analysis/analysishelper.cxx
+++ b/scaddins/source/analysis/analysishelper.cxx
@@ -26,7 +26,9 @@
 #include <o3tl/any.hxx>
 #include <rtl/math.hxx>
 #include <algorithm>
+#include <cmath>
 #include <memory>
+
 #include "analysisdefs.hxx"
 #include "analysishelper.hxx"
 #include <analysis.hrc>
@@ -1719,7 +1721,7 @@ void Complex::Power( double fPower )
 
 void Complex::Sqrt()
 {
-    static const double fMultConst = 0.7071067811865475;    // 
...2440084436210485 = 1/sqrt(2)
+    static const double fMultConst = M_SQRT1_2;
     double  p = Abs();
     double  i_ = sqrt( p - r ) * fMultConst;
 
@@ -1811,14 +1813,14 @@ void Complex::Ln()
 void Complex::Log10()
 {
     Ln();
-    Mult( 0.434294481903251828 );   // * log10( e )
+    Mult( M_LOG10E );
 }
 
 
 void Complex::Log2()
 {
     Ln();
-    Mult( 1.442695040888963407 );   // * log2( e )
+    Mult( M_LOG2E );
 }
 
 
diff --git a/scaddins/source/pricing/black_scholes.cxx 
b/scaddins/source/pricing/black_scholes.cxx
index 88bdfc999b35..98baa307c100 100644
--- a/scaddins/source/pricing/black_scholes.cxx
+++ b/scaddins/source/pricing/black_scholes.cxx
@@ -93,7 +93,7 @@ static double dnorm(double x) {
 }
 // cumulative normal distribution (see also ScInterpreter::integralPhi)
 static double pnorm(double x) {
-    return 0.5 * std::erfc(-x * 0.7071067811865475);
+    return 0.5 * std::erfc(-x * M_SQRT1_2);
 }
 
 // binary option cash (domestic)
diff --git a/stoc/test/testconv.cxx b/stoc/test/testconv.cxx
index 165f073912ed..5549779db117 100644
--- a/stoc/test/testconv.cxx
+++ b/stoc/test/testconv.cxx
@@ -29,6 +29,7 @@
 #include <com/sun/star/reflection/FieldAccessMode.hpp>
 #include <com/sun/star/registry/XImplementationRegistration.hpp>
 
+#include <cmath>
 #include <float.h>
 #include <stdio.h>
 
@@ -465,12 +466,12 @@ static sal_Int32 initBlocks( ConvBlock * pTestBlocks )
                                          // 
st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
     aVal <<= OUString("+.7071067811865");
     pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 
0, 0 );
-    aVal <<= (float)( .7071067811865 );
+    aVal <<= (float)( M_SQRT1_2 );
     pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
0, 0 );
                                          // 
st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
     aVal <<= OUString("3.14159265359");
     pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 
0, 0 );
-    aVal <<= (float)( 3.14159265359 );
+    aVal <<= (float)( M_PI );
     pTestBlocks[nElems++] = ConvBlock( aVal, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
0, 0 );
                                          // 
st,do,fl,u3,i3,u1,i1,by,bo,ch,tc,si,sa
     aVal <<= (float)( 5 );

Reply via email to