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:43

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 June 7 2006 13:30, Micah J. Cowan wrote:
> 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
IEEE is actually quite an old organization around 100 yrs, I believe.
IEEE has sections for power generation and transmission, and many others,
not just computers. 
> 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
> own).
> 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
> point.
> 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
> examples).
> 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).
For a long time, there has been no way in C to control floating pt modes
but I think recently some effort has been made. Rounding modes in
particular can be quite important in some computations.
I think C mostly goes with what is expedient with the hardware in use.
On x86, the hardware float registers are actually 82 bits. This can be
accessed directly with some compilers as long double But, OTOH, if you
specify double it will be expaned to long double when loaded into
a register. Now if it stays in the register through a series of operations,
the result can subtly different than if it was rounded to double after
every intermediate operation.
Look up Fateman at UC Berkeley for extensive discussions.
Richard Harke
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:
Sunset Systems
Who graciously hosts our website & mailing lists!