raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.27k stars 844 forks source link

Infinity plus minus-infinity should be nan #1572

Open dpgeorge opened 7 months ago

dpgeorge commented 7 months ago

The pico-sdk handles inf - inf in __wrap___aeabi_fsub, and correctly returns nan.

But inf + (-inf) is not handled correctly and returns inf, when it should return nan. It looks like __wrap___aeabi_fadd needs to have similar handling to fsub to detect this case.

Reproduction in MicroPython with pico-sdk v1.5.1:

>>> inf = float("inf")
>>> inf + (-inf)
inf
>>> -inf + inf
inf

But with subtraction it's correct:

>>> inf - inf
nan