[Verse-dev] verse build (in blender) fails....

Emil Brink emil at obsession.se
Wed Aug 23 10:12:31 CEST 2006


Emil Brink wrote:
(Replying to myself)

Eskil,

I think we really should look into dropping the V_REAL32_MAX and
V_REAL64_MAX values, and instead use "NAN" (not-a-value) where we
need to indicate special things using floating point fields.

I've done some investigations, and using NAN is not as hard as I
thought. Setting a value to NAN can be done by having a static
constant union, that contains the proper bits. ~0 works, so it's
a lot like what we already use for integers.

NAN has the following nice properties:

* It's testable by the isnan() function, which seems to be pretty
   quick (on my Linux system, it runs in less than 8 nanoseconds).
* Assigning a float NAN to a double variable preserves the NAN,
   and the other way around too.
* It should be independent on platform.
* It should have lesser chance of confusion with an actual float
   number, it doesn't "reserve" any of the space for numbers (since
   that is already done by the standard, I mean), unlike our MAX.
* It is what NAN is there for, so it's far cleaner.

We could sneak in a definition (and a macro) in something like v_network.h,
so that code that used to look like this (from v_gen_pack_g_node.c:63):

	buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], V_REAL64_MAX);

would be changed to look like this:

	buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], V_NAN);

or something. Of course, we could do separate pack/unpack functions for
it too, something like

	buffer_pos += vnp_raw_pack_nan_real64(&buf[buffer_pos]);

if we wanted to hide it further.

At unpack, the code would simply change from (line 276):

	if(x == V_REAL32_MAX || y == V_REAL32_MAX || z == V_REAL32_MAX)
to:
	if(isnan(x) || isnan(y) || isnan(z)).

I think it's nice to not rely on exact comparisons of actual (numerical)
floats, since many references say that is a bad thing to be doing. NAN
is a more stable value, so testing against it should be safer.

Care to comment?

Regards,

/Emil



More information about the Verse-dev mailing list