Menu

#2516 Division by zero with float should be a compiler warning not error

closed-fixed
Ben Shi
None
other
5
2021-03-17
2016-06-20
Alan Cox
No

A floating point divide by zero with exceptions masked is aNaN. The compiler should warn about these cases and optimize to NaN not error them as they may be deliberate portable(ish) ways to return NaN

eg

return 1.0/0.0

Related

Patches: #368

Discussion

  • Philipp Klaus Krause

    Usually 0.0/0.0 gives NaN.
    
    Philipp
    
     
  • Alan Cox

    Alan Cox - 2016-06-21

    Yep the code is using 0.0/0.0 for NaN and 1.0/0.0 for infinity

     
  • Ben Shi

    Ben Shi - 2016-08-24
    • status: open --> closed-fixed
    • assigned_to: Ben Shi
     
  • Ben Shi

    Ben Shi - 2016-08-24

    Fixed in revision #9742.

    1. Change divsion by zero from error to warning.
    2. 1.0 / 0.0 produces inf, and 0.0 / 0.0 produces nan.
    3. Add new library functions isnan() and isinf().
    4. Add a new test case for inf/nan result division.
     
  • Diego Herranz

    Diego Herranz - 2016-08-24

    Hi Ben,

    Check the comment header in sdcc/device/lib/isinf.c. It says NaN (Not a Number).

    Thanks!

     
  • Ben Shi

    Ben Shi - 2016-08-24

    Thanks. I have fixed it in revision #9743.

     
  • Maarten Brock

    Maarten Brock - 2021-03-17

    The regression test uses a subnormal number 1e-38, but the floating point division does not support subnormal numbers. I suggest to change it to 1.18e-38.

     

Log in to post a comment.