Fixed point arithmetic

Does anyone know a library for performing fixed point arithmetic in Python? Or does anyone have some sample code?

+6
python math
source share
3 answers

If you are interested in performing fixed-point arithmetic, there is a decimal module in the Python standard library that can do this.

In fact, it has a more flexible floating point ability than the built-in one. Flexible I mean that he:

  • Has β€œsignals” for various exceptional conditions (they can be configured to do different signal transmissions)

  • Has positive and negative infinities, as well as NaN (not number)

  • You can distinguish between positive and negative 0

  • Allows you to set a different rounding scheme.

  • Allows you to set your maximum values.

Altogether, it is convenient for millions of households .

+11
source share

The deModel package looks like you are looking.

+3
source share

Another option worth considering if you want to simulate the behavior of fixed-point binary numbers outside of simple arithmetic operations is the spfpm module. This will allow you to calculate the square roots, degrees, logarithms and trigonometric functions using fixed bit numbers. This is a pure-python module, so it does not provide maximum performance, but it can perform hundreds of thousands of arithmetic operations per second on 256-bit numbers.

0
source share

All Articles