Re: double vs float



On 3 Mar 2007 19:48:49 -0800, "santosh" <santosh.k83@xxxxxxxxx> wrote
in comp.lang.c:

subramanian100in@xxxxxxxxx, India wrote:
In the post with heading "Learning C - Scanf or Getch, or Getchar not
working correctly after first loop" that appears in today's list in
comp.lang.c,

it has been mentioned in the answer to this post, that double should
be preferred to float when space is not a constraint.

Can someone explain why double should be preferred to float ?

Usually it's because double corresponds more closely with the system's
native floating point type than float. Also, it gives more range and
precision than float, which is an important point when using floating-
point types.

What system is it that has "a" native floating point type, only one
that is, that corresponds more closely to double than float?

Your answer makes no sense at all, for several reasons:

1. If a platform only has a single floating point type supported in
hardware, and it meets the requirements for C's double, there is
nothing at all preventing the C implementation from using it for float
as well.

2. I can't think of any hardware architecture off-hand that has
hardware floating point for something suitable for a double, such as
64 bits or more, that does not also have hardware support for a
narrower floating point type.

On the other hand, I know of quite a few platforms where the opposite
is true, including 32-bit controllers and DSPs, namely that they have
hardware 32-bit floating point, which meets the C requirements for
float, but not a wider hardware floating point type.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: PPC floating equality vs. byte compilation
    ... all finite float x, and most platform C stringfloat routines these ... > The stalwart few who still use BeOS are mostly using Intel x86 hardware, ...
    (comp.lang.python)
  • Re: C++ anamaly
    ... > As I'm sure you know, there is calculation error in all floating point ... > dependent upon the hardware, but I'm sure that your teachers have told you ... with float you don't. ...
    (comp.lang.cpp)
  • Re: C++ anamaly
    ... >> As I'm sure you know, there is calculation error in all floating point ... >> dependent upon the hardware, but I'm sure that your teachers have told you ... > with float you don't. ...
    (comp.lang.cpp)
  • Re: half floating point type
    ... The surprisingly detailed list of historical floating point formats ... Half float pixel is a hardware floating point option for OpenGL graphics ... there is hardware support for it, since float will be about the same speed ...
    (comp.lang.c)
  • Re: pid_t data type
    ... If pid is negative but not -1, ... Since it needs to be used in comparisons it can't really be float... ... It seems like the platform can choose ... so if the platform can know what a floating point ...
    (comp.unix.programmer)