cnl
cnl copied to clipboard
Strange decimal literal behaviour
Describe the bug:
I'm seeing a weird representation of a _c literal decimal value such as 0.22_c. It seems turn into a massive value in the rep.
To Reproduce:
#include <cnl/all.h>
using namespace cnl::literals;
using fix24_8 = cnl::scaled_integer<int32_t, cnl::power<-8>>;
fix24_8 a = 0.22_c; // rep 4608
fix24_8 b = 0.22; // rep 56
Expected behavior:
Both reps should be 56.
Screenshots:
Double literal: 
Custom literal: 
Desktop (please complete the following information):
- OS: Win 10
- Compiler version GCC 9.3.1
- Compiler flags used
-DNDEBUG -std=c++17 -Iinclude - CNL version (or Git branch/SHA) https://github.com/maxgerhardt/cnl.git#v1.1.7-pio
Link to Compiler Explorer:
https://godbolt.org/z/vTjdz5sah
Unfortunately, the UDL, ""_c does not work with fractions. C++17 is only allowed to use integral NTTPs (non-type template parameters) and as 0.22 isn't even representable in binary floating-point, it's out of the running.
Sorry that it compiles at all! (It doesn't under v2 branch. Action: deprecate ""_c.)