0.0 / 0.0 = -NAN ?
Skybuck Flying <[email protected]> Sat, 30 Apr 2022 08:31:08 -0700 (PDT)
| Newsgroups | alt.comp.lang.borland-delphi |
|---|---|
| Message-ID | <[email protected]> |
When exception masks are all enabled to stop the processor from throwing floating point exceptions the following calculation produces a somewhat strange result: 0.0 / 0.0 = -nan (At least in Delphi). For now I will assume this is the case in C/C++ as well and with that I mean on x86/x64 which should and seems to be following IEEE 754 floating-point format. I am a little bit surprised by this and I want/need to know more. Where is this defined that 0.0 / 0.0 should be -NAN ?!? Problem is with the code, example: T := 0; D := 0.0 / 0.0; P := T * D; This screws up P. instead of P being zero, P is now also -NAN ?!? I find this very strange but ok. I guess a simple solution could be to set D to 0 explicitly for this case, is there perhaps another solution ? Maybe some kind of mask or rounding mode so that additional branch is not necessary ??? Bye for now, Skybuck.