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

Posit representation precision problem #281

Open
Yunfei-Ma-McMaster opened this issue Apr 22, 2022 · 1 comment
Open

Posit representation precision problem #281

Yunfei-Ma-McMaster opened this issue Apr 22, 2022 · 1 comment
Assignees

Comments

@Yunfei-Ma-McMaster
Copy link

For representation with posit in the command line, the decimal output does not have enough bits, which will confuse rounding results with accurate results.

For example:

posit 0.1

The output:

posit< 8,0>  = 00000110 : 0.09375
 posit< 8,1>  = 00010101 : 0.101562
 posit< 8,2>  = 00100101 : 0.101562
 posit< 8,3>  = 00110010 : 0.09375
 posit<16,1>  = 0001010011001101 : 0.10001
 posit<16,2>  = 0010010011001101 : 0.10001
 posit<16,3>  = 0011001001100110 : 0.099976
 posit<24,1>  = 000101001100110011001101 : 0.1
 posit<24,2>  = 001001001100110011001101 : 0.1
 posit<24,3>  = 001100100110011001100110 : 0.0999999
 posit<32,1>  = 00010100110011001100110011001101 : 0.1
 posit<32,2>  = 00100100110011001100110011001101 : 0.1
 posit<32,3>  = 00110010011001100110011001100110 : 0.0999999996
 posit<48,1>  = 000101001100110011001100110011001100110011001101 : 0.1
 posit<48,2>  = 001001001100110011001100110011001100110011001101 : 0.1
 posit<48,3>  = 001100100110011001100110011001100110011001100110 : 0.099999999999994
 posit<64,1>  = 0001010011001100110011001100110011001100110011001100110100000000 : 0.100000000000000006
 posit<64,2>  = 0010010011001100110011001100110011001100110011001100110100000000 : 0.100000000000000006
 posit<64,3>  = 0011001001100110011001100110011001100110011001100110011010000000 : 0.100000000000000006
 posit<64,4>  = 0011100100110011001100110011001100110011001100110011001101000000 : 0.100000000000000006

However, no posit can exactly represent 0.1. For instance, posit<32,2> (0.1) = 0.10000000009313226... not 0.1. The command line output seems to not have enough bits to cover the dynamic range of inaccurate representation.

@Ravenwater Ravenwater self-assigned this Apr 23, 2022
@Ravenwater
Copy link
Contributor

@Yunfei-Ma-McMaster thanks for pointing this out. As you can see from the command line options, the command posit is meant to give you a quick insight into the posit encoding, with the decimal values being there as guidance to scale.

As you can see in the output, the posit<64,#> values have 0's in their LSBs, which your decimal value of 0.1 should fill. What you observe there is that the command line interprets the value as a native double and that gets converted to a posit. As a double has fewer precision bits as the posit<64,#>, there is no information to fill the more precise posit bits.

On the roadmap are native decimal string converters for all number systems.

You will have full control over decimal output in the C++ classes, if you are studying the LSBs. There are also ULP methods to lift the ulp values.

Would you be interested to implement the decimal string converter for posits?

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