Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange decimal literal behaviour #911

Open
dzarda opened this issue Jul 1, 2021 · 1 comment
Open

Strange decimal literal behaviour #911

dzarda opened this issue Jul 1, 2021 · 1 comment

Comments

@dzarda
Copy link

dzarda commented Jul 1, 2021

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: obrazek

Custom literal: obrazek

Desktop (please complete the following information):

Link to Compiler Explorer:

https://godbolt.org/z/vTjdz5sah

@dzarda dzarda added the bug label Jul 1, 2021
@johnmcfarlane
Copy link
Owner

johnmcfarlane commented Jul 3, 2021

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants