jeudi 31 décembre 2015

Simulating nan/inf in a constexpr variable template

Is there a way to simulate nan/inf in a constant expression and without! using the C macros HUGE_VAL and INFINITY or any other for that matter! Plus, even with them, it still isn't constexpr.

I do not wish to use any standard function that the C++ standard library or the C standard library provides.

Of course the following doesn't compile. Compiler says constexpr variable must be initialized with a constant expression...

template<typename T = double>
constexpr T NaN = T(0.0 / 0.0);

Method that the MSVC compiler uses also doesn't compile:

template<typename T = double>
constexpr T NaN = T(1e+300); //with some changes, apparently having the float overflow

I know this is kind of broad, but this is for a library and I'm looking for some educated advice! Thanks!

Aucun commentaire:

Enregistrer un commentaire