PDA

View Full Version : Floating-point Constants



Diogo Teixeira
09-10-2007, 03:37 AM
Hello,
I'm part of a team working on free and open source implementations of the OpenKODE specification for many platforms.

While working on the Utility functions we noticed the following macros, defined in kd.h, may be a source of problems with some C and C++ compilers:

#define KD_INFINITY (1.0F/0.0F)
#define KD_NAN (0.0F/0.0F)
#define KD_HUGE_VALF ( 1.0F/0.0F)

Although they define perfectly valid floating-point arithmetic according to the IEC 559 / IEEE 754 standard, some standards specify that an explicit division-by-zero is the product of an ill-formed program. This usually
in either undefined behaviour or a compile time error. The latter occurs in the MS C Compiler but we think it's safe to assume that this may happen in other compilers.
Our current solution involves using platform dependent constants selected at compile time. However, we intend to fully comply with the spec.

What is the best way to deal with this issue?

tpr
11-30-2007, 05:22 AM
Hi

KD_NAN is not in the latest draft of the specification; it has been
replaced by a kdIsNan macro to tell whether a variable is NaN.

We have noticed the same problem with 1.0F/0.0F. To allow each
implementation to work round this in its own way, the specification now
states that KD_INFINITY is IEEE infinity, but does not mandate how your
kdplatform.h should achieve that.

Diogo Teixeira
11-30-2007, 05:44 AM
Hi Tim, thanks for responding.

We ended up modifying kd.h, following the same path as Acrodea.

Is there a time frame for the release of a new draft?

Our implementation for Win, WinCE, Mac and Linux is close to a release. We are wondering how well is OpenKODE being supported by ISV/HSVs?