Skip to content

Mean implementation for Fixed-Points #74

Answered by lschoe
manel1874 asked this question in Q&A
Discussion options

You must be logged in to vote

It's to prevent (unnecessary) loss of precision in the division by the public integer n. If we simply divide by n, which works out as multiplying by 1/n, we get a fixed-point number of the form 0.00001*** say, in binary, with a lot of leading zeros and few significant bits. Therefore, we shift this to the left to make it of the form 0.1*******, which represents 1/n with more significant bits. The product with the sum s is shifted back at the end. Note that e = n.bit_length()-1 to ensure 1/2 < 2**e / n <= 1 as written in the comment on line 58.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@manel1874
Comment options

Answer selected by manel1874
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants