0

In the book "C Primer Plus 5/e", I saw the author wrote:

C standard provides that a float has to be able to represent at least 6 significant figures and allow a range of at least 10^(-37) to 10^(+37).

But for doing so and using a natural size at the same time, it would require 4 bytes. So in fact, one can has a range from 10^(-63) to 10^(+63), see

http://en.wikipedia.org/wiki/Floating_point#Internal_representation

So I got a question in my mind: Why C standard choose the requirement of a range at least 10^(-37) to 10^(+37). Of course, there may be a consideration of the speed of computation. But beyond this reason, is there any reason not to use the full 32 bits space?

Filip Roséen - refp
  • 62,493
  • 20
  • 150
  • 196
user565739
  • 1,302
  • 4
  • 23
  • 46
  • 2
    Because it doesn't require that `float`s be represented using IEEE-754. –  Feb 11 '13 at 18:48
  • Not sure what you mean by that? A 32-bit floating point number could be arranged in a few different ways, but you end up with roughly 6 decimal digits and roughly 10^(+/-37) whatever you do. All 32 bits ARE used in standard floating point, but the specification doesn't mandate that the bits are used in a particular pattern - if the implementer decides to use one more bit for exponent, and one bit less for the mantissa, that would be allowed and fine within the spec. Still using all 32 bits. Of course, if the floating point unit uses 31 bits, as long as it supports the range, that's OK too. – Mats Petersson Feb 11 '13 at 19:03
  • Thanks. I made a mistake (forget to change to base 10) so I got a wired result and asked the question. The answer Petersson gave pointed this. – user565739 Feb 11 '13 at 19:06

1 Answers1

5

The C standard is written in the way it is, to allow the C language to implemented on a wide range of machines, with a wide range of hardware. By limiting the actual representation REQUIRED, there are more possible machines that can use C "without breaking the rules".

There are floating point processors (and in particular, there WERE) that doesn't necessarily use IEEE-754.

Further, I think your 10^(-63) .. 10^(+63) is a misunderstanding. A 32-bit float has a range of 2^(+/-127), which means about 10^(+/-37) (2^127 ~= 10^37).

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227