Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Representation of floating-point numbers

5 views
Skip to first unread message

Skarmander

unread,
May 15, 2006, 2:12:16 PM5/15/06
to
This question is a spinoff from a thread in comp.lang.c. Does the standard
guarantee that the real number 1 is exactly representable as a
floating-point number? Does it guarantee that the C integer 1 converts to
this number? Does it guarantee that the floating-point number converts back?

I notice the standard defines floating-point numbers in terms of a "model".
What does the second paragraph of section 5.2.4.2.2 mean, when it says "a
floating-point number [..] is defined by the following model"? Does it mean
all solutions of the equation presented are exactly representable
floating-point numbers? If so, this seems to include 1 for every possible
value of the constants involved.

Also, is there any change between the C89 and C99 semantics and requirements
for floating-point numbers, aside from the optional explicit IEC 60559 support?

S.

kuy...@wizard.net

unread,
May 15, 2006, 2:48:58 PM5/15/06
to
Skarmander wrote:
> This question is a spinoff from a thread in comp.lang.c. Does the standard
> guarantee that the real number 1 is exactly representable as a
> floating-point number? ...

Not explicitly, but I don't see how any implementation that can
meaningfully be described in terms of the model in 5.2.4.2.2 would be
unable to represent 1, exactly.

> ... Does it guarantee that the C integer 1 converts to
> this number? ...

6.3.1.4p2 says that if the value it can be represented exactly, it must
convert exactly.

> ... Does it guarantee that the floating-point number converts back?

6.3.1.4p1 says that conversion to integer type truncates the fractional
part, and leaves the integral portion. Therefore, a value representing
1.0 exactly must be converted to 1.

...


> Also, is there any change between the C89 and C99 semantics and requirements
> for floating-point numbers, aside from the optional explicit IEC 60559 support?

That I can't answer - I don't have access to any detailed description
of C89.

Eric Sosman

unread,
May 15, 2006, 3:03:07 PM5/15/06
to

Skarmander wrote On 05/15/06 14:12,:


> This question is a spinoff from a thread in comp.lang.c. Does the standard
> guarantee that the real number 1 is exactly representable as a
> floating-point number?

Yes, in 5.2.4.2.2 paragraphs 1 and 2, plus paragraph 8's
requirement that zero is within the range [emin,emax].

> Does it guarantee that the C integer 1 converts to
> this number?

Yes, in 6.3.1.4 paragraph 2.

> Does it guarantee that the floating-point number converts back?

Yes, in 6.3.1.4 paragraph 1.

> I notice the standard defines floating-point numbers in terms of a "model".
> What does the second paragraph of section 5.2.4.2.2 mean, when it says "a
> floating-point number [..] is defined by the following model"? Does it mean
> all solutions of the equation presented are exactly representable
> floating-point numbers? If so, this seems to include 1 for every possible
> value of the constants involved.

The model is a "model" because the Standard does not
specify values for its parameters (except to place various
restrictions and requirements on their ranges). Plug in
values for the parameters and the model becomes a definition
of a particular floating-point implementation.

Given the parameter values, all solutions to the equation
of paragraph 2 are representable floating-point numbers. Since
paragraph 8 implies that the exponent can be zero, 1 is always
in the representable set.

> Also, is there any change between the C89 and C99 semantics and requirements
> for floating-point numbers, aside from the optional explicit IEC 60559 support?

C89 uses essentially the same model, but specifies it
less exhaustively. 1.0 and 1.0F and 1.0L are all representable,
and convert to and from 1 as in C99.

--
Eric....@sun.com

Michal Necasek

unread,
May 15, 2006, 3:11:48 PM5/15/06
to
kuy...@wizard.net wrote:

> That I can't answer - I don't have access to any detailed description
> of C89.
>

Australian standard AS 3955-1991, equivalent of ISO 9899-1990, can be
had from the ANSI web store (http://webstore.ansi.org/) for mere US$ 103.

The floating-point model in C90 is the same, but the specification is
less detailed. Notably there is no mention of NaNs whatsoever, and
infinity is mentioned only in passing as something that "implementation
may support".


Michal

Douglas A. Gwyn

unread,
May 15, 2006, 5:30:19 PM5/15/06
to
Skarmander wrote:
> Also, is there any change between the C89 and C99 semantics and requirements
> for floating-point numbers, aside from the optional explicit IEC 60559 support?

As I recall, there are now (C99) expression evaluation contexts
in which it is required that the implementation produce one of
the two nearest exactly representable values, which (again as I
recall) wasn't a C89 requirement.

0 new messages