Re: double vs float



Jack Klein wrote:
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.


After reading your points I realise I may have been incorrect in my
assumptions.

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

Well the IA32 architecture has an 80 bit hardware floating point type,
to which the C double would correspond more closely than a 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.

Except for the fact that one of float's purpose is to reduce memory
requirements.

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.

I stand corrected.

.



Relevant Pages

  • Re: How many float values in range 0f - 1f inclusive?
    ... or a bit pattern outside the range I ... gave that corresponds to a floating point number in 0f through 1f. ... In Java float is 32 bites. ...
    (comp.lang.java.help)
  • Re: How many float values in range 0f - 1f inclusive?
    ... or a bit pattern outside the range I ... gave that corresponds to a floating point number in 0f through 1f. ... In Java float is 32 bites. ...
    (comp.lang.java.help)
  • Re: How many float values in range 0f - 1f inclusive?
    ... Each bit pattern in the range Float.floatToIntBitsthrough ... Float.floatToIntBitscorresponds to a float value in the specified ... gave that corresponds to a floating point number in 0f through 1f. ... In Java float is 32 bites. ...
    (comp.lang.java.help)
  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... And now a question about something else: why do you use floating ... use then to copy a float into a char *1. ... binary representation doesn't resemble a string like "123.46343" ...
    (comp.lang.c)
  • Re: float vs. double?
    ... There have been repeated myths that float is faster than double. ... In antique machines, the ... Note that the floating-point ALU of Intel chips supports an 80-bit floating point number, ... is different precision being stored? ...
    (microsoft.public.vc.mfc)