Subject: Re: Converting long double to integer types
To: NetBSD/sparc64 Port <port-sparc64@NetBSD.org>
From: Holger Weiss <lists@jhweiss.de>
List: port-sparc64
Date: 11/05/2007 20:19:46
* der Mouse <mouse@Rodents.Montreal.QC.CA> [2007-11-05 10:33]:
> > On 4.99.30, the following code spits out "x=2 y=1":
>
> > long double ld = 1.9;
> > int x = ld;
> > int y = (double)ld;
>
> > AFAICS, "x=2" clearly violates the standard, no?
>
> Which standard?
C99 (at least):
| When a finite value of real floating type is converted to an integer
| type other than _Bool, the fractional part is discarded (i.e., the value
| is truncated toward zero). If the value of the integral part cannot be
| represented by the integer type, the behavior is undefined.
[ http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf (6.3.1.4, 1) ]
I haven't checked other standards.
Holger