From: Guillaume Melquiond (guillaume.melquiond_at_[hidden])
Date: 2003-12-12 10:18:29
Le ven 12/12/2003 à 15:48, Dan W. a écrit :
> > It seems you didn't really understand. It doesn't happen with big or
> > small integers. It happens with integers in the middle (between 2^23 and
> > 2^24). With the current implementation, when a floating-point is an
> > integer in the correct target range, you are not sure at all that the
> > integer you get after the cast is the same as before.
> I think I'm starting to understand... Is it that when you say to the
> hardware "add .5" the nearest value to .5 it thinks is 1 ? I think I get it.
It's because in standard floating-point arithmetic rounded by default,
"<float> 8388609. + 0.5 = 8388610.".
> Any chance I could look at the code for numeric_cast<> without going
> through CVS?
The code isn't available through CVS. There is a version in the Yahoo
file group, and Fernando posted another here:
> (Maybe I can figure out some assembler trick to, at least, not use a branch.)
No need to go as far as using assembly language. There are C functions
that work just fine like nearbyint or rint (the second one is usually
faster). And if you are really looking for assembler, the frndint
instruction is available on x86 for exemple.