Questions tagged [fixed-point]

Questions about fixed-point arithmetic, done using a set number of decimal places. For the combinators used to encode recursion, use [fixpoint-combinators] instead. For the numerical method, use [fixed-point-iteration] instead. For the fixedpoint engine of Z3, use [z3-fixedpoint] instead.

Fixed point arithmetic uses a fixed radix position to do calculations, instead of a variable amount (floating point). Instead of representing numbers using the IEEE mantissa-and-exponent format, numbers are represented as integers which are scaled by a fixed amount. It can be faster and is, within its regime, more precise than floating-point.

Most questions deal with finding a suitable fixed-point library for [insert language here], as most languages lack fixed-point arithmetic in their standard libraries (although some have one natively). Also, different types of fixed point number exist based on the number of decimal points included (and thus accuracy) - see the Q format.

511 questions
2
votes
4 answers

How many bits are used for the exponent

I'm writing a few functions that will convert float/double to fixed point and back. Does anyone know the best way to determine the number of bits used for the exponent portion of a float or double? I was hoping to using something from…
waffleman
  • 4,159
  • 10
  • 39
  • 63
2
votes
3 answers

How to implement multiplication in fixed-point

I want to implement multiplication in C and in fixed-point with scalable fraction bitwidth (i.e. from 1 bit to 30 bit), I know the simplest way is like this: typedef int32_t fixedpt; typedef int64_t fixedptd; fixedpt fixedpt_mul(fixedpt A, fixedpt…
Wade Wang
  • 536
  • 6
  • 11
2
votes
1 answer

128.128 Unsigned fixed point Division in Solidity

I am currently trying to figure out a concrete way to perform fixed point division on two 128.128 uint256 numbers. This seems like a fairly straightforward thing, but haven't been able to code a solution up. For two 64.64 fixed point numbers the…
0xOsiris
  • 247
  • 2
  • 17
2
votes
1 answer

How to write this floating point code in a portable way?

I am working on a cryptocurrency and there is a calculation that nodes must make: average /= total; double ratio = average/DESIRED_BLOCK_TIME_SEC; int delta = -round(log2(ratio)); It is required that every node has the exact same result no matter…
user491880
  • 4,709
  • 4
  • 28
  • 49
2
votes
1 answer

Why does a fixed-point scaling factor tend to be a power of two?

Assume we have two floating point values: 1.23 and 4.56. To represent and add these in a machine without floating point support, we will have to fall back to fixed point representation. So we pick the number 100 as a scaling factor, simply to get…
Dan
  • 2,694
  • 1
  • 6
  • 19
2
votes
4 answers

How to decide when to use fixed point arithmetic over float?

How to decide when to use fixed point arithmetic over float? I have read that, fixed point is used when there is no Floating point unit in the processor. When there is no FPU, does that mean 'float' datatype is not supported ?
Hp179
  • 21
  • 3
2
votes
1 answer

Python rounding with Decimal module to specified decimal places

Question: How could I make Python's Decimal module round to a specified decimal place instead of rounding to a specified precision (significant figure) while evaluating an arithmetic operation? Info I have been using the Decimal module in Python to…
user12128336
2
votes
1 answer

What is the problem with this fixed point conversion from floating point in c?

I am trying to convert floating point to fixed point because the hardware does not have floating point acceleration. I cannot seem to find my mistake for the variable screen_X the value is always 320.0. The precision is Q38,26 (edit useful bits are…
2
votes
1 answer

Converting from IEEE-754 to Fixed Point with nearest rounding

I am implementing a converter for IEEE 754 32 bits to a Fixed point with S15.16 in a FPGA. The IEEE-754 standard represent the number as: Where s represent the sign, exp is the exponent denormalized and m is the mantissa. All these values…
Diego Ruiz
  • 187
  • 2
  • 11
2
votes
1 answer

Matrix multiplication in Fixed Point for 16 bits

I need perform the matrix multiplicatión between differents layers in a neural network. That is: W0, W1, W2, ... Wn are the weights of the neural netwotk and the input is data. Resulting matrices are: Out1 = data * W0 Out2 = Out1 * W1 Out3 = Out2 *…
Diego Ruiz
  • 187
  • 2
  • 11
2
votes
2 answers

Overflows in fixed point math

As part learning exercise, part hobby project, I am implementing my own interpretation of the Cooley-Tukey FFT algorithm on an AVR using fixed point math. I haven't dealt much with fixed point math before, and am wondering how best to go about part…
MattyZ
  • 1,541
  • 4
  • 24
  • 41
2
votes
1 answer

Fixed Point Development

I'm working on some fixed point coding these days. If I have a bunch of 16 bit samples from an ADC and I do multiplication with a 16 bit filter coefficient, the result could be a 32 bit fixed point number right? Now that's fine because I'm targeting…
NickHalden
  • 1,469
  • 2
  • 20
  • 31
2
votes
2 answers

How are large and small Floating point values represented with Fixed point

I know that on machines without Floating Point Units, such numbers should either be represented in fixed point or FPU is emulated using libc. In the former case, how are very large and very small FPU values repined in fixed point? my understanding…
Dan
  • 577
  • 1
  • 3
  • 9
2
votes
1 answer

Right shift operation on 32 bit variable

I want to do right shift of 33 on a 32 variable and store the result into a float variable. For suppose, the value is 1717986812. When we right shift by 33, we expect the value to be 0.2. But when I do 1717986812 / (1<<33), I am getting some other…
rkc
  • 111
  • 8
2
votes
2 answers

Negative fixed point number representation

I am writing a generic routine for converting fixed-point numbers between decimal and binary representations. For positive numbers the processing is simple, however when things come to negative ones I found divergent sources. Someone says there is a…
Eddie Deng
  • 1,399
  • 1
  • 18
  • 30