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

The size of ac_fixed changes between signed and unsigned #18

Open
agustinhurquiza opened this issue Nov 30, 2021 · 1 comment
Open

The size of ac_fixed changes between signed and unsigned #18

agustinhurquiza opened this issue Nov 30, 2021 · 1 comment

Comments

@agustinhurquiza
Copy link

I am observing that the ac_fixed sizes change when I use unsigned 32 bits.

Here is an example:

ac_fixed<32, 16, true> x = 3.14;
std::cout << "Sizeof: " << sizeof(x) << " bytes\n";
[Out] Sizeof: 4 bytes

ac_fixed<32, 16, false> x = 3.14;
std::cout << "Sizeof: " << sizeof(x) << " bytes\n";
[Out] Sizeof: 8 bytes

This happens in version AC Datatypes v4.4.1

I'm not sure this is a bug, but I did find this effect strange, forcing me to change my code to accommodate this.

Compilation Info:

* Oracle Linux Server release 7.9
* g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44.0.3)
* g++ example.cpp -o run -I ../include/ -O3 -Werror -Wall -g -std=c++11
@jmartinl
Copy link

I don't think it's a bug, because of the following reason:
ac_fixed template is defined as
class ac_fixed : private ac_private::iv<(W+31+!S)/32>
That is, the number of elements in iv is the number of 32 bit elements required to hold the value. But also whether it's signed or not, influences the sum.
If S is true (signed) and W is 32, you get indeed (32+31)/32 (=1), but if S is false (unsigned), you get (32+32)/32 (=2), as one bit more is needed for the sign.

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

No branches or pull requests

2 participants