Boost logo

Boost :

From: Eric Ford (eford_at_[hidden])
Date: 2001-09-12 21:22:47

> How about having a seperate low-level fp library similar to the
> integer library. This could define IEEE_single, IEEE_double,
> as well as providing portable versions of is_nan(), is_infinity().

I think a relatively low level templatized interface to the floating
mathematical functions provided by the standard C library might be a
good idea.
It would be much simpler (than what we've recently been talking about
a more general mathematical libarary) and could be useful for building
a more complex library on top of. There are several possible levels
of complexity for such an interface. I'll list some of the first that
come to mind, using sqrt as an example. (Obviously, functions taking
two arguments would need an additional argument for all 4 versions,
and an additional template argument for the latter 2 versions.)

1. T sqrt<T>(T x) would call sqrt, sqrtf, or sqrtl as appropriate.
2. T sqrt<T, ErrorHandelerT = ErrorHandelerDefaultT >(T x,
ErrorHandelerT& EH = ErrorHandelerT() ) would provide the above and
use the provided error handeler to optionally bracket it by calls to
fetestexcept and feclearexcept (or whatever other checks were
necessary) and deal with any errors.
3. ReturnT sqrt<ReturnT,ArgumentT = ReturnT >(ArgumentT x) would be
like 1, but choose the higher precission type for performing the
calculation and perform the necessary conversions.
4. ReturnT sqrt<ReturnT,ArgumentT = ReturnT, ErrorHandelerT& EH =
ErrorHandelerT = ErrorHandelerDefaultT >(ArgumentT x, EH =
ErrorHandelerT() ) would perform both the conversion of 3 and the
checking of 2

One option would be to only provide these for functions existing in
standard c library. Another option would be to implement additional
versions for other types. (e.g. Although int sin(int x) makes little
sense and should probably give a compiler error, int pow(int x, int n)
does make sense. exp2, exp10, min, max, abs, and rounding functions
are the other types that I can think of that this makes sense for.)

I've coded up most of the fp versions using ugly macros and put them
if anyone wants to take a look.

As for nan, according to the GNU C library manual, ISO C99 provide
fpclassify, isnan, isinf, etc.. What's the shortcoming of this


Boost list run by bdawes at, gregod at, cpdaniel at, john at