From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-12-12 15:42:02
Dan W. wrote:
> > 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.
> Not familiar with those,
Those are C99 functions.
Unfortunately, many C++ compilers don't support them yet.
> but I just came up with something that should
Apart from the fact that modern CPUs have FPUNITs matching integer
arithmetic speed, which means that not using the fp instructions dierctly is
not needed in a _general_purpose_ (not domain specific) library, a
fundamental problem with your code is that it's placed on the wrong layer.
Boost is intended to provide high-level (as opposed to low-level) PORTABLE
A function with x86 inline assember is anythiung but portable and
This doesn't mean that users of the boost libraries cannot leverage the
power of targeted low-level domain specific implementations.
Your code is good as a replacement of the Int2FloatRounder policy.
The library allows you to specify this policiy precisely so you can plug in
your favorite rounding code. But the default implementation should not try
to be too smart compromising portability.
Anyway, notice that this problem is specific of the "Round" policiy which
rounds to nearest; but this policy is not the only rounding policy available
and it is not the default.
If you just use the default converter policiy, float to integer will
Truncate just as the C++ does.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk