[eigen] Proposal: Include Constants to NumTraits |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: [eigen] Proposal: Include Constants to NumTraits*From*: Pavel Holoborodko <pavel@xxxxxxxxxxxxxxx>*Date*: Fri, 6 Apr 2012 13:24:06 +0900

Eigen is well designed to be invariant of scalar types.

However I think there is one point for improvement - mathematical constants.

They tied to scalar type (to its precision, e.g. double vs. multiple precision) and frequently needed in computations.

Now, in true generic code in order to use matching-to-scalar constant we have to do something like: pi = acos(Scalar(-1)) (FFT module).

Obviously this can (and should) be improved.

We already handle machine epsilon by NumTraits. Why don't we include other constants to NumTraits?

So that we can use them as follows

typedef typename NumTraits<Scalar>::Real RealScalar;

const RealScalar Pi = NumTraits<RealScalar>::Pi();

const RealScalar Euler = NumTraits<RealScalar>::Euler();

const RealScalar Log2 = NumTraits<RealScalar>::Log2();

const RealScalar Catalan = NumTraits<RealScalar>::Catalan();

...

// Use constants in the code below

// ...

This would make writing generic code much easier (and code will be cleaner).

This is especially important for multiple precision types - where computing of const. takes a lot of resources.

Additional layer of abstraction will allow us to cache const. without recomputing them every time.

For built-in scalar types these functions will be one-liners without any overhead.

Also it has sense to include Inf(), Nan() as special values (similar to std::numeric_limits<Scalar> ).

Would appreciate any comments.

(Boost has similar library - e.g. boost::math::constants::pi<Scalar>();)

**Follow-Ups**:**Re: [eigen] Proposal: Include Constants to NumTraits***From:*Gael Guennebaud

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] uniform spaced cpx sinusoid via rootfinding, was Re: FFT module thoughts** - Next by Date:
**Re: [eigen] Proposal: Include Constants to NumTraits** - Previous by thread:
**Re: FFT module thoughts, was Re: [eigen] Eigen 3.0.5 Could NOT find FFTW** - Next by thread:
**Re: [eigen] Proposal: Include Constants to NumTraits**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |