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
9 answers

How to treat a struct with two unsigned shorts as if it were an unsigned int? (in C)

I created a structure to represent a fixed-point positive number. I want the numbers in both sides of the decimal point to consist 2 bytes. typedef struct Fixed_t { unsigned short floor; //left side of the decimal point unsigned short…
snakile
  • 52,936
  • 62
  • 169
  • 241
2
votes
1 answer

Is there a way to use OpenCV Mat_ with custom class?

I have some algorithm in OpenCV and I want to rewrite it using fixed point value representation. I found class for fixed point arithmetic here: https://github.com/eteran/cpp-utilities. I'd like to know if there's some elegant way to use Mat_…
BartekM
  • 106
  • 3
  • 8
2
votes
4 answers

How to evaluate polynomials with fixed point arithmetic without overflow?

I would like to evaluate a polynomial on a real time embedded system that has only 32 bit integer hardware. For this reason, I am trying to use fixed point arithmetic. How can I avoid overflows without also imposing ridiculous limitations on the…
Filipp
  • 1,843
  • 12
  • 26
2
votes
1 answer

Fixed-point number types in Postgres?

The Postgres database I manage contains many columns containing numbers between 0 and 100, with a fixed (never more than 3, usually 2) number of decimal places. Most of these numbers cluster around their respective averages, and thus repeat a lot,…
virnovus
  • 129
  • 1
  • 12
2
votes
2 answers

How to define new primitive data type and its behavior in Scala

Is there a way to create a new data type where I define the number of bits and arithmetic rules in Scala? I have a program that uses 32 bit floats but am trying to study how will affect the results. I want to rewrite the program to do addition and…
2
votes
1 answer

lerp for integers or in fixed point math

Is there an elegant way to do linear interpolation using integers? (To average ADC measurements in microcontroller, ADC measurements are 12bit, microcontroller works fine with 32bit integers). Coefficient f is in [0, 1] range. float lerp(float a,…
DikobrAz
  • 3,557
  • 4
  • 35
  • 53
2
votes
4 answers

declaring a variable with only 2 decimal points in C

I am trying to declare a variable eLon with only 1 decimal place so that if I have the code: elon=359.8 printf("eLon = %f\n",eLon); and the output will be eLon = 359.8 However the output I get is: eLon = 359.7999999. How I know that I could…
jms1980
  • 1,017
  • 1
  • 21
  • 37
2
votes
0 answers

convert int 32 to q31 or f32

I am trying to understand exactly how to do this. I know how fixed point and floating point notations work, but I was wondering how I can convert from int32 to q31 or f32. If I understand q31 correctly it leaves 31 bits for the fractional part and…
scarlso9
  • 195
  • 3
  • 14
2
votes
1 answer

Arm assembler right shifting after multiplpy long?

Newbie ARM assembler question. I am writing my first arm assembler program and I am trying to code this C fragment. int x = somevalue1 << 12; // s19.12 int y = somevalue2 << 12; // s19.12 int a = somevalue3 << 12; // s19.12 int b = somevalue4…
Sandy
  • 21
  • 2
2
votes
1 answer

Fixed point multiplication "solution," crazy or viable?

Assume this much: I'm using a 16.16 fixed point system. System is 32 bit. CPU has no floating point processor. Overflow is pretty imminent for multiplication for anything larger than 1.0 * 0.4999 To make one last assumption... lets say the values…
Maximus
  • 8,351
  • 3
  • 29
  • 37
2
votes
1 answer

Can we convert every Algorithm in fixed point?

I have developed a Algorithm in MATLAB using floating point variable. In my algortihm I am doing eigen value decomposition ,rotation, transformation of matrices, inverse of matrices, division , addition and multipications of matrices several…
2
votes
1 answer

Overflow using Fixed-Point Chebyshev Method

I have an algorithm in an embedded system that needs to calculate sin(theta), sin(2*theta), sin(3*theta), etc) with Q15 fixed-point arithmetic. sin(theta) and cos(theta) are generated using a LUT/interpolation combo, but I'm using the Chebyshev…
Darko
  • 589
  • 1
  • 7
  • 18
2
votes
1 answer

Wrong results multiplying two 32 bit numbers in C

I am trying two multiply to matrices in C and I cant understand why I get these results... I want to do : Btranspose * B #include #include #include #include #define LOW_WORD(x) …
Franx
  • 87
  • 1
  • 10
2
votes
1 answer

QR algorithm implementation 3x3 fixed point

I want to find the eigenvalues and eigenvectors of a 3x3 matrix (mostly if not always symmetric!!). My numbers are stored in fixed-point format (16.16 to be exact). Note that I don't mind much about the performance, but simply implementing an…
Franx
  • 87
  • 1
  • 10
2
votes
1 answer

Eigenvectors, eigenvalues fixed point calculation in C

** Edited ** I tried changing the mentioned Jacobi algorithm to fixed point using libfixmath but I am not getting right results. What did I miss?? edited Jacobi code makefile C newbie here. I somehow got my self in the deep and i cant find my way…
Franx
  • 87
  • 1
  • 10