Questions tagged [fixed-point-arithmetics]

A fixed-point number representation is a real data type for a number that has a fixed number of digits after (and sometimes also before) the radix point. Fixed-point number representation can be compared to the more complicated floating-point number representation.

In computing, a fixed-point number representation is a real data type for a number that has a fixed number of digits after (and sometimes also before) the radix point (after the decimal point '$.$' in English decimal notation). Fixed-point number representation can be compared to the more complicated (and more computationally demanding) floating-point number representation.

Fixed-point numbers are useful for representing fractional values, usually in base $2$ or base $10$, when the executing processor has no floating point unit (FPU) as is the case for older or low-cost embedded microprocessors and microcontrollers, if fixed-point provides improved performance or accuracy for the application at hand, or if their use is more natural for the problem (such as for the representation of angles).

A value of a fixed-point data type is essentially an integer that is scaled by an implicit specific factor determined by the type. For example, the value $1.23$ can be represented as 1230 in a fixed-point data type with scaling factor of $\frac 1 {1000}$, and the value $1,230,000$ can be represented as $1230$ with a scaling factor of $1000$. Unlike floating-point data types, the scaling factor is the same for all values of the same type, and does not change during the entire computation.

The scaling factor is usually a power of $10$ (for human convenience) or a power of $2$ (for computational efficiency). However, other scaling factors may be used occasionally, e.g. a time value in hours may be represented as a fixed-point type with a scale factor of $\frac 1 {3600}$ to obtain values with one-second accuracy.

The maximum value of a fixed-point type is simply the largest value that can be represented in the underlying integer type multiplied by the scaling factor; and similarly for the minimum value.

To convert a number from a fixed point type with scaling factor $R$ to another type with scaling factor $S$, the underlying integer must be multiplied by $R$ and divided by $S$; that is, multiplied by the ratio $\frac R S$. Thus, for example, to convert the value $1.23 = \frac {123} {100} $ from a type with scaling factor $R=\frac 1 {100}$ to one with scaling factor $S=\frac 1 {1000}$, the underlying integer $123$ must be multiplied by $\frac {\frac 1 {100}} {\frac 1 {1000}} = 10$, yielding the representation $\frac {1230} {1000}$. If $S$ does not divide $R$ (in particular, if the new scaling factor $S$ is greater than the original $R$), the new integer will have to be rounded. The rounding rules and methods are usually part of the language's specification.

To add or subtract two values of the same fixed-point type, it is sufficient to add or subtract the underlying integers, and keep their common scaling factor. The result can be exactly represented in the same type, as long as no overflow occurs (i.e. provided that the sum of the two integers fits in the underlying integer type). If the numbers have different fixed-point types, with different scaling factors, then one of them must be converted to the other before the sum.

To multiply two fixed-point numbers, it suffices to multiply the two underlying integers, and assume that the scaling factor of the result is the product of their scaling factors. This operation involves no rounding. For example, multiplying the numbers $123$ scaled by $\frac 1 {1000}$ ($0.123$) and $25$ scaled by $\frac 1 {10}$ ($2.5$) yields the integer $123×25 = 3075$ scaled by $\frac 1 {1000}\times\frac 1 {10} = \frac 1 {10000}$, that is $\frac {3075} {10000} = 0.3075$. If the two operands belong to the same fixed-point type, and the result is also to be represented in that type, then the product of the two integers must be explicitly multiplied by the common scaling factor; in this case the result may have to be rounded, and overflow may occur. For example, if the common scaling factor is $\frac 1 {100}$, multiplying $1.23$ by $0.25$ entails multiplying $123$ by $25$ to yield $3075$ with an intermediate scaling factor of $\frac 1 {10000}$. This then must be multiplied by $\frac 1 {100}$ to yield either $31$ ($0.31$) or $30$ ($0.30$), depending on the rounding method used, to result in a final scale factor of $\frac 1 {100}$.

To divide two fixed-point numbers, one takes the integer quotient of their underlying integers, and assumes that the scaling factor is the quotient of their scaling factors. The first division involves rounding in general. For example, division of $3456$ scaled by $\frac 1 {100}$ ($34.56$) and $1234$ scaled by $\frac 1 {1000}$ ($1.234$) yields the integer $3456 \div 1234 = 3$ (rounded) with scale factor $\frac {\frac 1 {100}}{\frac 1 {1000}} = 10$, that is, $30$. One can obtain a more accurate result by first converting the dividend to a more precise type: in the same example, converting $3456$ scaled by $\frac 1 {100}$ ($34.56$) to $3,456,000$ scaled by $\frac 1 {100000}$, before dividing by $1234$ scaled by $\frac 1 {1000}$ ($1.234$), would yield $3456000 \div 1234 = 2801$ (rounded) with scaling factor $\frac {\frac 1 {100000}} {\frac 1 {1000}} = \frac 1 {100}$, that is $28.01$ (instead of $30$). If both operands and the desired result all have the same scaling factor, then the quotient of the two integers must be explicitly multiplied by that common scaling factor.

Source: Wikipedia

14 questions
3
votes
1 answer

Composite functions and fixed point free property

Given 2 functions: $f: X \to X$ and $g: X \to X$, $f$ and $g$ are one-to-one $f$ and $g$ are fixed point free composite functions $f \circ g$, $\; g \circ f$, $\; f^2 \equiv f \circ f\;$ and $\;g^2 \equiv g \circ g$ are fixed point free Is it true…
2
votes
0 answers

Find the equilibrium point for a single neural network layer

Given a matrix $\mathbf{W}\in\mathbb{R}^{n\times n}$ and a vector $\mathbf{b}\in\mathbb{R}^{n}$, find the equilibirum for the following single-layer neural network: $$ f(\mathbf{x})=\text{ReLU}(\mathbf{Wx+b}), $$ where…
2
votes
2 answers

Understanding error propagation in fixed-point multiplication

I'm writing a test suite that checks the correctness of a fixed-point arithmetic library that I wrote. Specifically, it deals with Q4.4 numbers, i.e. 4 integer bits and 4 fractional, so its precision is 1/16. The test suite produces two rational…
1
vote
1 answer

Calculating the fixed-point representation of (1 - √0.5) to arbitrary levels of precision

I have a constant 0.29289321881345247559915563789515..., which can be calculated using the equation (1 - √0.5) and then transformed into fixed-point format in order to be used with various sizes of unsigned integers. See the following table for…
1
vote
1 answer

Formalizing a self referential sentence

In The logic of provability, by G. Boolos, we are asked to ponder about this statement: If this statement is consistent, then you will have an exam tomorrow, but you cannot deduce from this statement that you will have an exam tomorrow. I tried…
Jsevillamol
  • 4,759
0
votes
1 answer

Proving that $\sin(\lambda x)$ only has one fixed point, if $\lambda$ is smaller than one.

I've been trying to prove that $\sin(\lambda x)$ only has a single fixed point (over all the real number) for $0< \lambda < 1$. I've thought of using the fixed point theorem, since it's obvious that $|sin'(\lambda x)| < 1$. But, the other criteria…
0
votes
0 answers

Can one do Conjugate Gradient for non-floating point arithmetics?

So the last few years I have used Krylov subspace methods (mostly Conjugate Gradient) for solving various kinds of problems in science and engineering, but in all of these applications I have only needed to consider floating point arithmetics.…
0
votes
1 answer

Elchanan Mossel’s Dice Paradox using fixed point updating

The problem: You throw a dice until you get 6. What is the expected number of throws (including the throw giving 6) conditioned on the event that all throws gave even numbers. The following is the solution from Berend Roorda using fixed point…
0
votes
1 answer

Solution to rational Diophantine equations in fixed point

I'm trying to solve the following system of equations for $p$ and $q$, given fixed integers $x$, $y$ and $c$: $$r = {{c x + p} \over {c y + q}} \ , \, \, \, r \in \mathbb{Z}$$ where $$\{x, y, p, q, c\} \in \mathbb{Z}$$ $$0 \leq y \lt x$$ $$0 \leq…
0
votes
0 answers

Banach and Caristi fixed point theorems

We all know that caristi fixed point theorem is a generalisation of banach fixed point theorem . We are able to derivate banach fixed point theorem from caristi fixed point theorem by taking a special function . I know this special function and I…
user344374
0
votes
1 answer

Fixed to float in archived (font2openvg) code

i found this link from some forum, so i thought the source code must have been useful to some: font2openvg.cpp.txt The question is, why divide 4096 to convert a fixed to float? float convFTFixed( const FT_Pos &x ) { return (float)x / 4096.0f; }
noypi
  • 103
0
votes
1 answer

Converting Decimal to Fixed Point Number

I am having trouble to get the intuition behind the following approach: We take the fraction point (say: .642) and continuously multiply by 2, taking whatever ends up right of the point as our next number (either 0 or 1) after the fixed point in the…
Kevin Wu
  • 147
  • 2
  • 7
0
votes
2 answers

How many bits do I need to store a given fraction?

Unlike integers, decimal fractions cannot be directly represented in binary. Therefore, what is the procedure to find how many bits to use to express a given binary fraction are sufficient? Basically I am trying to understand that for a given range…
quantum231
  • 1,207
0
votes
1 answer

Matrices over integer fields to solve complex polynomials.

Inspired by the fruitful answer to this question regarding numerically solving polynomial equations in terms of simpler fields (in that case representing real numbers as fractions of integers), I though I would try to take it a step further. Knowing…