summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-08-04 13:06:46 -0500
committerJeff Epler <jepler@gmail.com>2020-08-04 14:45:45 -0500
commitd3fb6c96da9dc38ea24a221e11f05cdbbddb34c9 (patch)
treecb69f21e8fbf8a767af3ddf97aa4158e0309529b /lib
parent710c2dc54b7c97088890b084f0ed0ab5132011e8 (diff)
libm: ef_rem_pio2.c: Save ROM-tables at the expense of speed
This function computes the remainder of a value `x` modulo pi/2, to high precision. It does this by dividing the flotaing point values into several ranges by magnitude, and applies successively slower but more accurate algorithms. The last two steps, one covering values up to around 2^7 * pi/2 (called "medium size") and a final one covering all possible float values, require big tables. By eliminating the "medium size" case, a table and some code are removed from the binary. This makes some cases take longer, but saves hundreds of bytes. It does _NOT_ affect the result, only the speed. ``` [desktop python] >>> sum(math.sin(2.**i) for i in range(21)) 1.4206898748939305 [trinket m0, before change to ef_rem_pio2.c] >>> sum(math.sin(2.**i) for i in range(21)) 1.42069 [trinket m0, after change to ef_rem_pio2.c] >>> sum(math.sin(2.**i) for i in range(21)) 1.42069 ```
Diffstat (limited to 'lib')
-rw-r--r--lib/libm/ef_rem_pio2.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/libm/ef_rem_pio2.c b/lib/libm/ef_rem_pio2.c
index bbb73097d..c6dbe4587 100644
--- a/lib/libm/ef_rem_pio2.c
+++ b/lib/libm/ef_rem_pio2.c
@@ -145,6 +145,7 @@ pio2_3t = 6.1232342629e-17; /* 0x248d3132 */
return -1;
}
}
+#if CIRCUITPY_FULL_BUILD
if(ix<=0x43490f80) { /* |x| ~<= 2^7*(pi/2), medium size */
t = fabsf(x);
n = (__int32_t) (t*invpio2+half);
@@ -180,6 +181,11 @@ pio2_3t = 6.1232342629e-17; /* 0x248d3132 */
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
else return n;
}
+#else
+ // Suppress "defined but not used" diagnostics
+ (void) j; (void) fn; (void) r; (void) t; (void) w; (void) pio2_3t;
+ (void) pio2_3; (void) invpio2; (void)half; (void)npio2_hw;
+#endif
/*
* all other (large) arguments
*/