mercredi 2 juin 2021

Determining in template function the shortest float type that faithfully represents integer type parameter

template< typename int_type >
bool foo( int_type argument )
{
    float_type value = argument; // float_type must faithfully represent argument.
    ...
}

That is, I'd like to derive within the template function the shortest floating point type float_type that has at least as many significant digits as the template parameter int_type.

foo<int16> should use float.

foo<int32> should use double.

foo<int64> should use long double.

Is this doable without specialization?

Aucun commentaire:

Enregistrer un commentaire