Casting and Optimization Flags

Joseph D. Wagner wagnerjd@prodigy.net
Wed Dec 11 11:14:00 GMT 2002


> casting floats to integers does not round; it truncates
> 
> To round, simply add 0.5 to your float.

GOOD GRIEF NO! DON'T DO THAT! That will just compound the problem.

Use:
ceil(x) - rounds up to nearest int
floor(x) - rounds down to nearest int

Requires:
#include <cmath>

Joseph Wagner



More information about the Gcc-help mailing list