Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Add support for FixedPointParameters with negative number of integral bits. #406

Open
ghost opened this issue Oct 5, 2018 · 2 comments
Open

Comments

@ghost
Copy link

ghost commented Oct 5, 2018

This is required to support fixed point formats with value ranges like [-0.5, 0.5), e.g.
Q-1.16 on 16 bits:
0x8000 -> -0.5 (32768/2^17)
0x7FFF -> 0.499984

Q-2.17 on 16 bits:
0x8000 -> -0.25 (32768/2^17)
0x7FFF -> 0.249992

For those formats number of integer bits needs to be set to negative value.

@sguiriec
Copy link

sguiriec commented Oct 5, 2018

Can you clarify why you have put these numbers of 16 bits container and not 32 bits?

Q format is defined as per https://en.wikipedia.org/wiki/Q_%28number_format%29

So Q1.16 number should be define on 32 bits container.

@ghost
Copy link
Author

ghost commented Oct 8, 2018

"For a given Qm.n format, using an m+n bit signed integer container with n fractional bits..."
m can also be negative if one want to represents small numbers. In my examples I did not include the sign bit in the m value, after adjusting to match the wikipedia samples it would be:

  1. Q0.16: m = 0; n = 16 ; container m+n (0 + 16) -> 16bit; range [-(2^(0-1), 2^(0-1)- 2^-16]; resolution 2^-16

  2. Q-1.17: m = -1; n = 17 ; container m+n (-1 + 17) -> 16bit; range [-(2^(0-2), 2^(0-2)- 2^-17]; resolution 2^-17

Similar examples can be created for 32 bit containers. The issue is about support for fixed point parameters where the resolution is being increased by limiting the range of representable values.
For example, using 16bit containers for brevity:

Q16.0, range [-32768, 32767), resolution 1  (degenerative case)
...
Q2.14,  range [   -2,    2), resolution 2^-14
Q1.15,  range [   -1,    1), resolution 2^-15
Q0.16,  range [-0.5, 0.5), resolution 2^-16
Q-1.17, range [-0.25, 0.25), resolution 2^-17
Q-2.18, range [-0.125, 0.125), resolution 2^-18
...

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

No branches or pull requests

1 participant