Tweak util::fixed_point comments

This commit is contained in:
Nikita Lisitsa 2025-09-05 19:35:36 +03:00
parent 56d23480b0
commit 0210b61540

View file

@ -20,7 +20,7 @@ namespace psemek::util
* represented as an (I+F)-bit-wide standard signed integer type, and the * represented as an (I+F)-bit-wide standard signed integer type, and the
* stored value is interpreted as representing the fraction (value / 2^F). * stored value is interpreted as representing the fraction (value / 2^F).
* It is capable of representing values in the range from (- 2^(I+F-1)) / 2^F * It is capable of representing values in the range from (- 2^(I+F-1)) / 2^F
* to (2^(I+F-1) - 1) / 2^F, with a fixed precision of 2^F. * to (2^(I+F-1) - 1) / 2^F, with a fixed precision of 1 / 2^F.
* *
* For example, * For example,
* *
@ -40,7 +40,9 @@ namespace psemek::util
* separate question...). * separate question...).
* *
* Multiplication and division are implemented by casting to a 2x wider integer type, * Multiplication and division are implemented by casting to a 2x wider integer type,
* to increase precision and prevent overflows. * to increase precision and prevent overflows. Note that the result is still truncated
* to the original size, i.e. multiplying two 16.16 fixed-points gives a 16.16 fixed-point
* as well.
* *
* Typical usage of this class would be to make a type alias like * Typical usage of this class would be to make a type alias like
* *
@ -345,6 +347,8 @@ namespace psemek::util
if (p < 0) if (p < 0)
return fixed_point<I, F, S>(1) / pow(x, -p); return fixed_point<I, F, S>(1) / pow(x, -p);
// Binary exponentiation algorithm
fixed_point<I, F, S> result(1); fixed_point<I, F, S> result(1);
while (p > 0) while (p > 0)
{ {