Skip to content

Commit 5c32756

Browse files
committed
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 ```
1 parent 1c53f91 commit 5c32756

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/libm/ef_rem_pio2.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pio2_3t = 6.1232342629e-17; /* 0x248d3132 */
145145
return -1;
146146
}
147147
}
148+
#if CIRCUITPY_FULL_BUILD
148149
if(ix<=0x43490f80) { /* |x| ~<= 2^7*(pi/2), medium size */
149150
t = fabsf(x);
150151
n = (__int32_t) (t*invpio2+half);
@@ -180,6 +181,11 @@ pio2_3t = 6.1232342629e-17; /* 0x248d3132 */
180181
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
181182
else return n;
182183
}
184+
#else
185+
// Suppress "defined but not used" diagnostics
186+
(void) j; (void) fn; (void) r; (void) t; (void) w; (void) pio2_3t;
187+
(void) pio2_3; (void) invpio2; (void)half; (void)npio2_hw;
188+
#endif
183189
/*
184190
* all other (large) arguments
185191
*/

0 commit comments

Comments
 (0)