How to template float/double constants?

Hi,

I have a templated class that can either use float or double as type.
My question is now:
What do I do with constant numbers in the code?
Let's assume I have a multiplication by 0.5:
In the case of float type, I want: 0.5f
In the case of double type, I want: 0.5

One answer would be to check for every constant the type and doing
an if/else, but this is very annoying with lots of constants.
Is there a better way?

The code using these constants infer their type automatically
by the assignment, that's why I have to take care of the constants.

Thanks
meleagrosy
1
2
3
4
5
6
template < typename T > struct A
{
    static constexpr T half = T(1) / T(2) ;
    static constexpr T two = T(2) ;
    // ...
};
Topic archived. No new replies allowed.