l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2006 Jun 07 14:03

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] C and IEEE-754
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] C and IEEE-754

On Wed, Jun 07, 2006 at 02:48:36PM -0500, Ken Bloom wrote:
> On Wed, Jun 07, 2006 at 03:41:02PM -0400, Peter Jay Salzman wrote:
> > I started to read:
> > 
> >    http://www.cs.princeton.edu/introcs/91float/
> > 
> > and came across an interesting comment:
> > 
> >    "Java uses a subset of the IEEE 754 binary floating point standard to
> >    represent floating point numbers and define the results of arithmetic
> >    operations. Most machines conform to this standard, although some
> >    languages (C, C++) do not guarantee that this is the case."
> > 
> > It's a poorly written paragraph, but seems to say that C and C++ don't
> > guarantee adherence to the IEEE 754 standard.  If this really is the case,
> > why don't they?
> I suppose if your hardware supports something else instead of
> IEEE-754, then a conforming C/C++ implementation can use the hardware,
> rather than having to emulate IEEE-754.

In fact, IIRC, C predates IEEE('s very existance as an orginazation) by
quite a bit. But the best format for every machine isn't IEEE-754, IBM
and Cray have used their own formats for floating point (though, AIUI,
for the most part they have supported IEEE-754 in addition to their

Note that C doesn't even have particular requirements on the radix used
by the floating point model (i.e., it doesn't have to be 2. Hell, it
could be 10!).

However, you can test for the existence of a macro, __STDC_IEC_559__,
whose existence guarantees conformity to IEC 60559:1989 floating point
(which is the current designation for ANSI/IEEE 754-1989, which was also
designated IEC 559:1989 before it went to 60559. If that macro is
defined, then you are free to assume the usual semantics for floating

C++ uses a completely different approach . You use the numeric_limits<>
type defined in the <limits> header:

  if (std::numeric_limits<double>::is_iec559) {

AFAICT, the __STDC_IEC_559__ macro is only available in C99; my draft
copy of C90 doesn't mention it (but does refer to IEEE 754 in some

However, <float.h> provides a number of definitions useful in describing
the floating-point model used, and there are certain guarantees made
about them (such as a double being convertable to 10 decimal digits and
back without loss of information).

Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.