[goffice] math: provide also a go_pow



commit 75defe302c1750461970e82ba4fa049cac27c443
Author: Morten Welinder <terra gnome org>
Date:   Sat Nov 6 17:33:30 2021 -0400

    math: provide also a go_pow
    
    This is a thin wrapper than just checks for 10^i and uses go_pow10
    in that case.

 goffice/math/go-math.c | 21 +++++++++++++++++++--
 goffice/math/go-math.h |  2 ++
 2 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/goffice/math/go-math.c b/goffice/math/go-math.c
index f8a4f2bc..51b0b216 100644
--- a/goffice/math/go-math.c
+++ b/goffice/math/go-math.c
@@ -374,6 +374,15 @@ go_pow10 (int n)
        return pow (10.0, n);
 }
 
+double
+go_pow (double x, double y)
+{
+       if (x == 10 && y > G_MININT && y < G_MAXINT && y == floor (y))
+               return go_pow10 ((int)y);
+       return pow (x, y);
+}
+
+
 static int
 strtod_helper (const char *s)
 {
@@ -593,14 +602,14 @@ go_pow10l (int n)
        // because it is known not to be what it should be.
 
 #define TEN(n) ONE(n ## 0),ONE(n ## 1),ONE(n ## 2),ONE(n ## 3),ONE(n ## 4),ONE(n ## 5),ONE(n ## 6),ONE(n ## 
7),ONE(n ## 8),ONE(n ## 9)
-       static const double pos[] = {
+       static const long double pos[] = {
 #define ONE(n) 1e+0 ## n ## L
                TEN(00), TEN(01), TEN(02), TEN(03), TEN(04), TEN(05), TEN(06), TEN(07), TEN(08), TEN(09),
                TEN(10), TEN(11), TEN(12), TEN(13), TEN(14), TEN(15), TEN(16), TEN(17), TEN(18), TEN(19),
                TEN(20), TEN(21), TEN(22), TEN(23), TEN(24), TEN(25), TEN(26), TEN(27), TEN(28), TEN(29)
 #undef ONE
        };
-       static const double neg[] = {
+       static const long double neg[] = {
 #define ONE(n) 1e-0 ## n ## L
                TEN(00), TEN(01), TEN(02), TEN(03), TEN(04), TEN(05), TEN(06), TEN(07), TEN(08), TEN(09),
                TEN(10), TEN(11), TEN(12), TEN(13), TEN(14), TEN(15), TEN(16), TEN(17), TEN(18), TEN(19),
@@ -617,6 +626,14 @@ go_pow10l (int n)
        return powl (10.0L, n);
 }
 
+long double
+go_powl (long double x, long double y)
+{
+       if (x == 10 && y > G_MININT && y < G_MAXINT && y == floor (y))
+               return go_pow10l ((int)y);
+       return powl (x, y);
+}
+
 /*
  * go_strtold: A sane strtold.
  * @s: string to convert
diff --git a/goffice/math/go-math.h b/goffice/math/go-math.h
index e7d7f227..ee1c25d2 100644
--- a/goffice/math/go-math.h
+++ b/goffice/math/go-math.h
@@ -35,6 +35,7 @@ double go_rint (double x);
 int go_finite (double x);
 double go_pow2 (int n);
 double go_pow10 (int n);
+double go_pow (double x, double y);
 
 double go_strtod (const char *s, char **end);
 double go_ascii_strtod (const char *s, char **end);
@@ -83,6 +84,7 @@ long double go_fake_truncl (long double x);
 int go_finitel (long double x);
 long double go_pow2l (int n);
 long double go_pow10l (int n);
+long double go_powl (long double x, long double y);
 
 long double go_strtold (const char *s, char **end);
 long double go_ascii_strtold (const char *s, char **end);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]