Thread overview |
---|
June 13, 2003 cast(int) real BUG | ||||
---|---|---|---|---|
| ||||
int main() { real a = 0.9; int b = cast(int) a; printf("%i", b); return 0; } This prints -2147483648... The compiler casted 'a' to uint. If I change it to "printf("%u", b);" it correctly prints 0. Anyway, does a casted-to-int floating-point always floor the value? |
June 13, 2003 Re: cast(int) real BUG | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | int main() { real a = 0.9; ulong b = cast(ulong) a; printf("%u", cast(uint) b); return 0; } Prints: 1717987328 In hex it would be: 0x66666800 I have no idea about what's happening here. ulong b = cast(ulong)cast(float) a; <- this fails as well ulong b = cast(ulong)cast(double) a; <- OK |
June 14, 2003 Re: cast(int) real BUG | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | "Dario" <supdar@yahoo.com> wrote in message news:bccpsa$14je$1@digitaldaemon.com... > int main() > { > real a = 0.9; > int b = cast(int) a; > printf("%i", b); > return 0; > } > > This prints -2147483648... > The compiler casted 'a' to uint. > If I change it to "printf("%u", b);" it correctly prints 0. This looks like a bug with %i. > Anyway, does a casted-to-int floating-point always floor the value? Yes. |
Copyright © 1999-2021 by the D Language Foundation