Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-09-13 13:33:24

----- Original Message -----
From: Paul A. Bristow <boost_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, September 13, 2001 2:41 PM
Subject: RE: [boost] Re: Math Functions - is_nan & is_infinity

> Yes please provide your work/ideas on this so far.
> Other contributions/views?
> Paul
> PS This looks a minor issue, but I feel it is cruical to
> making widespread use of using the NaN etc parts of the IEEE spec.

I'm attaching here the headers: 'generic_math.h, 'cvt_n.h',
They are intended to be the basic building block for arbitrary type numeric

They are not boostified, they are a exact copy of my own files, so there is
a lot to discuss but it could be used as a starting point.

The basic idea is actually very simple.

Declares a namespace in which there are template versions of the usual math
functions and some others I added.
A conversion function: cvt_n<U>(T const&) is used in the implementation of
the template functions so arbitrary types are internally mapped to double so
there always a default implementation available.
For those types for which a particular function exist you just specialize
the template function.

In particular, template functions is_nan,is_inf just shortcut into the
compiler supplied versions (most <float> headers contains this).
With this, the problem of supplying the internal functions for a specific
compiler/platform is isolated from user code, and support can be added per
context as soon as we know how.
I think that the only way around portability here is to supply the
compiler-specific functions used here by hand in those compilers that just
don't have it. I know this just defers the problem but isolates it very
well from the users of the templated 'is_nan'.

Note: this headers uses the 'method 1' as suggested by Eric Ford. We need to
consider the other alternatives that he suggested.

Contains the definition of cvt_n<>. I'm not sure if this can be replaced by
As you will see in the header itself, the function is designed to *expand*
into the most efficient conversion code possible.
For instance, double d = cvt_n<double>(2.0) compiles *exactly* like: double
d = 2.0 ;

Encapsulates traits classes that provide a *consistent* way to determine and
compare the valid ranges of a given type (used in cvt_n<>)
It is mainly used in order to cope with the inconsistency in the meaning of
numeric_limits<T>::min for floating point and integer types.

Hope this helps, as time permit me, I am willing to participate in this

Fernando Cacciola
Sierra s.r.l.

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