I need some like this:
const float ratio = 1/60;
How to do this?
Exactly as you have done but tell the compiler the values in the expression are floats with a "f" suffix
const float ratio = 1.0f/60.0f;
You don't really need constexpr
, this will work in C
or C++
:
const float ratio = 1./60;
If you need a ratio, as opposed to the result of one, you can use std::ratio:
constexpr one_sixtieth = std::ratio<1, 60>();
constexpr auto n = one_sixtieth.num;
constexpr auto d = one_sixtieth.den;
It comes with a set of useful compile time operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With