Closed Klummel69 closed 3 years ago
Thanks for reporting this! Your suggested fix looks good as well.
This allows constants to be defined at compile time without the detour via from_fixed_point<..>....
True, but using this constructor would still rely on floats during compilation. I'm not confident enough that every compiler's compile-time handling of floats is the same. Removing floating point numbers in every step of the process is safer.
True, but using this constructor would still rely on floats during compilation. I'm not confident enough that every compiler's compile-time handling of floats is the same. Removing floating point numbers in every step of the process is safer.
I don't think this is a problem. As far as I know constexpr variables must be resolved at compile time. Therefore no float operations should be left at runtime. I use a compiler here that allows float at compile time but throws errors when using float at runtime.
Alternatively you could define a method "fraction", which use 2 numbers in fraction notation (numerator by denominator). This would give us a good representation of a floating/fixed point number.
// Example
static constexpr fpm::fixed_16_16 delta = fpm::fixed_16_16.fraction(1234, 1000); // Or similar...
Thanks for the update, as always blazing fast!
The following code generates an error message under different clang versions, because std::round() is not a constexpr function in C++11/14.
I suggest the following workaround: replace std::round()
On Godbolt you can see the behavior (without fpm header)
https://godbolt.org/z/34cns5fnK
Advantage: This allows constants to be defined at compile time without the detour via from_fixed_point<..>....