[Verse-dev] Today's enemy: V_REAL64_MAX

Emil Brink verse-dev@blender.org
Fri, 30 Apr 2004 10:09:42 +0200 (MEST)


Eskil,

I'm fairly happy with the cleaning effort, but there is at least one
thing I still dislike: the V_REAL64_MAX value used for signaling that
a value is missing.

There are several issues I have with this:

1. I'm not completely certain that the floating point implementations
   are stable enough that providing a literal constant with 17 sig-
   nificiant digits is trustworthy. It might be, I just have this re-
   flex that says "don't compare floating point numbers for equality".
2. It should be better abstracted. The symbol should be e.g.
   V_REAL64_UNKNOWN or something that communicates the *purpose* of
   setting a value to this magical constant, the nature of the con-
   stant itself is not interesting.
3. I would prefer functions to do the setting and testing, since that
   abstracts it even further. Or macros, if we're feeling performance
   anxiety. E.g. VERSE_REAL64_IS_UNKNOWN() to test.

The IEEE754 standard specifies exact bit patterns that are *not*
numbers, like NaN ("not a number") and inf (infinity). It would make
a great deal of sense to use e.g. NaN for this purpose, since it's
then a lot clearer and more clean ("all floating point numbers can be
used for vertex coordinates, use NaN to signal deletion").

The best way to generate a NaN I've found so far, if one doesn't want
to use the bit-by-bit method, is to compute 1.0/0.0.

To test for NaN, there is a C function called isnan() but it seems to
be outside the ANSI standard and would have to be provided by our API
in any case, perhaps as the macro mentioned above or as a true func-
tion.

/Emil