Re: Bit representation of a float
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Wed, 15 Aug 2007 18:13:26 +0000 (UTC)
In article <46c2f842.1382768205@xxxxxxxxxxxxxx>,
Richard Bos <rlb@xxxxxxxxxxxxxxxxxxxxxx> wrote:
You can rely on the output making _some_ sense, since the representation
of floating point numbers must follow certain patterns as laid out in
the Standard. You must have a fixed base and precision for each floating
point type, and each FPN must have a sign, an exponent, and a fixed
number of significand digits. However, how these numbers are represented
in the underlying bits is not specified by the Standard, so you may not
immediately recognise the pattern; but it must be there.
I have just reviewed the C89 wording on it, and I'm not -convinced-
that the precision must be fixed.
FLT_RADIX must be a constant. Everything else in <float.h> is
allowed to be non-constant expressions ("non-constant" is specifically
mentioned.)
FLT_MANT_DIG and kin are defined in C89 as
number of decimal digits, q, such that any floating point number
with q decimal digits can be rounded into a floating-point
number with p radix b digits and back again without change
to the q decimal digits
It seems to me that if you had some kind of variable precision, then
FLT_MANT_DIG and kin could be the worst-case numbers, with the
possibility that you might get noticably more accuracy on some values.
The whole s/b/e/p/f[k] floating point model is just that, a -model-,
an abstraction, that need not necessarily be followed internally as long
as you can get the necessary behaviours to work out.
Not that I can see any good reason to implement anything else -- not even
any half-baked reason. But if someone implemented a format that (say)
had variable amounts of significant storage and padded the rest
[e.g., some kind of toaster where 1/32 was the finest resolution needed
for 99% of the calculations], then I don't know that that'd be ruled out.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
.
- References:
- Bit representation of a float
- From: Gary Baydo
- Re: Bit representation of a float
- From: Richard Bos
- Bit representation of a float
- Prev by Date: Re: How to implement a Hash Table in C
- Next by Date: Re: beginner fscanf question
- Previous by thread: Re: Bit representation of a float
- Next by thread: Re: Bit representation of a float
- Index(es):
Relevant Pages
|