You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
math: powf: make a precision vs size trade-off for flash-constrained builds
.. by calculating x**y as exp(y*log(x)) after some suitable initial
tests.
The most notable anomaly I found is that powf() is used in number parsing
and it changes from the correct
>>> float("10000000") - float("1e7")
0.0
to the incorrect
>>> float(10000000) - float("1e7")
4.0
Size savings is 1352 bytes on Trinket M0, and the existing more accurate
behavior is preserved on boards with CIRCUITPY_FULL_BUILD.
I investigated whether "exponentiation by squaring" gave more accurate results
for integer exponents, but it did not.
New behavior:
```
>>> sum( (-1.1) ** x for x in range(-6, 6))
-0.574803
>>> sum( 10. ** y for y in range(-6, 6))
111111.0
>>> sum( y ** (4/3) for y in range(-6, 6) ) # Complex values not supported
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <genexpr>
ValueError: complex values not supported
>>> sum( y ** (-4/3) for y in range(1, 6) )
1.90242
```
Original behavior:
```
>>> sum( (-1.1) ** x for x in range(-6, 6))
-0.574803
>>> sum( 10. ** y for y in range(-6, 6))
111111.0
>>> sum( y ** (4/3) for y in range(-6, 6) ) # Complex values not supported
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <genexpr>
ValueError: complex values not supported
>>> sum( y ** (-4/3) for y in range(1, 6) )
1.90242
```
Desktop Python behavior:
```
>>> sum( (-1.1) ** x for x in range(-6, 6))
-0.574803366641059
>>> sum( 10. ** y for y in range(-6, 6))
111111.111111
>>> sum( y ** (4./3) for y in range(-6, 6) ) # Complex values not supported
(5.921675597487694-29.140714142379153j)
>>> sum( y ** (-4./3) for y in range(1, 6) )
1.9024215285409685
```
0 commit comments