double to int conversion leads to crazy results

Horst von Brand vonbrand@sleipnir.valparaiso.cl
Fri Dec 31 20:54:00 GMT 1999


Markus Werle <markus@lufmech.rwth-aachen.de> said:
> // Maybe I am too tired today, but look at that output:
> //  > g++ --version
> // 2.95.2
> 
> // > uname -a
> // Linux aachen 2.2.10 #12 Mon Nov 29 00:16:46 MET 1999 i586 unknown
> 
> // > g++ ConvertNumbersToStrings.C && a.out

[...]

> // static_cast<int>(2030) = 2029           !!!!!!!!!!
> // static_cast<int>(20300) = 20299         !!!!!!!!!!

What your << prints is a rounded double, the static_cast<> truncates.
-- 
Horst von Brand                             vonbrand@sleipnir.valparaiso.cl
Casilla 9G, Viña del Mar, Chile                               +56 32 672616



More information about the Gcc-bugs mailing list