l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
December 2: Social Gathering
Next Installfest:
TBA
Latest News:
Nov. 18: Officers elected
Page last updated:
2006 Jun 07 14:03
Events
 Meetings
 Installfests
 Demos
 Photos
Services
 Library
 LERT
 Jobs
 Documents
Interact
 Mailing Lists
 - Search
 - Archives
 Chat (IRC)
 Social Networks
About Us
 Members
 Projects
 Testimonials
 Call for Speakers
 Why Not MS?
 Finances
 Sponsors

^Home
?Search
?News & RSS
?Calendar
@Contact Us
$Buy Stuff
=Printable


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
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).

-- 
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
facebook
LUGOD Group 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
1105 Kennedy Place, Suite 1, Davis, CA 95616
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:
No Starch Press
For book donations.