Re: floats doubles long doubles

From: Jack Klein (jackklein_at_spamcop.net)
Date: 11/26/03


Date: Wed, 26 Nov 2003 05:12:00 GMT

On 25 Nov 2003 20:19:44 -0800, daniel4d2001@yahoo.com (dan) wrote in
comp.lang.c++:

> Can someone tell me the difference between these three data types?
>
> Thanks
>
> Daniel

There may no be any.

The C++ language inherits these floating point types from C. C and
C++ allow, but does not require, three different floating point types.

Each floating point type has certain minimum specifications that it
must meet.

A 32 bit IEEE single precision representation fully meets the
requirements of a float in C and C++, and is what almost all platforms
and compilers use today. It does not meet the requirements for the
wider types.

A 64 bit IEEE double precision representation fully meets the
requirements of both double and long double in C and C++. This is
what almost all platforms and compilers use today for double.

Some hardware architectures (example, Intel x86) provide hardware
support for even higher precision, such as the Intel FPU 80 bit
extended precision format. Some hardware platforms do not.

Even on platforms where there is hardware support for long double to
have more precision than double, there is no requirement for a
compiler to support it. The requirements for double and long double
in C and C++ are identical.

For example, Microsoft 32 bit compilers for x86 do not support the 80
bit extended precision format, although their older 16 bit compilers
did. So double and long double are exactly the same representation in
Visual C++ programs. On the other hand, other compilers for the same
processors such as Borland and GCC do use the 80 bit format, so long
double has more precision and range than double.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq


Relevant Pages

  • Re: Motorized knee" on the mill works great now!
    ... I consider it (extra precision in registers) a bug, ... claimed the hardware got wrong. ... For floating point, it allows one to sum a large number of ...
    (rec.crafts.metalworking)
  • Re: computing exp(1.0) on SPARC.
    ... I'm no expert in floating point but do use it. ... So I wouldn't expect computations in double precision to ... But the issue here is not simply different compilers on different ... check with gcc on AIX - there is no valid IBM compiler. ...
    (comp.unix.solaris)
  • Re: Fixed point Vs Floating point
    ... Is this how the hardware design is done? ... Floating point has more dynamic range for the given number of bits ... requirements but doesn care as much about the precision. ... fitting fixed-point math to the algorithm is simple, ...
    (sci.electronics.design)
  • Re: why still use C?
    ... >> fairly low degree of precision, but it needs to be provided ... >> a radix that is a power of 10. ... > binary floating point. ... It's faster (given the hardware), simpler, ...
    (comp.lang.c)
  • Re: Fixed point Vs Floating point
    ... Is this how the hardware design is done? ... Floating point has more dynamic range for the given number of bits ... requirements but doesn care as much about the precision. ... fitting fixed-point math to the algorithm is simple, ...
    (sci.electronics.design)