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
```
This commit is contained in:
Jeff Epler 2020-08-04 13:06:46 -05:00
parent 710c2dc54b
commit d3fb6c96da
1 changed files with 6 additions and 0 deletions

View File

@ -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
*/