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

converting int to float (or double)

0 views
Skip to first unread message

Guy Dallaire

unread,
Nov 21, 1995, 3:00:00 AM11/21/95
to
Hi,

Does that code guarantee that the value 3.0 (exactly) will be stored
in variable a and b ?

void test(void)
{
int i=3;
float f;
double d;

a=i;
b=i;
}


*** God only knows if God exists... ***


Dik T. Winter

unread,
Nov 23, 1995, 3:00:00 AM11/23/95
to
In article <48sms5$r...@sparcserver.lrz-muenchen.de> ua3...@sun2.lrz-muenchen.de (Kurt Watzka) writes:
> dall...@megatoon.com (Guy Dallaire) writes:
...

> > int i=3;
> > float f;
> > double d;
> > a=i;
> > b=i;
...
> Maybe you wanted to know whether they will be stored in f and d
> exactly?

Making that assumption, I do not think that the standard has any
requirements on the precision of the conversion. So even if 3.0
would fit in a float or a double, there is no guarantee that the
result will be that value. (And you may be in for some surprises,
there have been machines were 0.0 was not a valid floating point
number, *all* floating point numbers were non-zero.)
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/

0 new messages