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
3
votes
1 answer

Ada fixed-point rounding of multiplication

The following code prints TRUE that means 0.0191*0.0191 is evaluating to 0.0003 and 0.0192*0.0192 is evaluating to 0.0004. However: 0.0191*0.0191 = 0.00036481 0.0192*0.0192 = 0.00036864 Had the rounding happened at the threshold of 0.00035, the…
Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52
3
votes
0 answers

How to make sure no floating point code is used

does anyone know of an automated way to make sure that a piece of C code doesn't use any floating point? Either compiler options, gcc, msvc, clang or some static analysis tool. I looked in the gcc compiler options and for coverity checkers, but…
hko
  • 548
  • 2
  • 19
3
votes
1 answer

How to include vhdl fixed point library to ghdl-0.33?

I am new to ghdl simulator,and using ghdl on windows. I have setup ghdl (ghdl-0.33-win32) on my computer and tried out simple adder code and it worked. I currently need to simulate some math equations where I have used David Bishop's fixed and…
komto909
  • 187
  • 1
  • 10
3
votes
2 answers

Fixed point arithmetic

I'm currently using Microchip's Fixed Point Library, but I think this applies to most fixed point libraries. It supports Q15 and Q15.16 types, respectively 16-bit and 32-bit data. One thing I noticed is that it does not include add, subtract,…
Thomas O
  • 6,026
  • 12
  • 42
  • 60
3
votes
2 answers

What's the best multiplication algorithm for fixed point where precision is necessary

I know, I know, people are probably going to say "just switch to floating point", but currently that is not an option due to the nature of the project that I am working on. I am helping write a programming language in C++ and I am currently having…
3
votes
3 answers

Python: create fixed point decimal from two 32-bit ints (one for int portion, one for decimal)

I have a 64-bit timestamp unpacked from a file with binary data, where the top 32 bits are the number of seconds and the bottom 32 bits are the fraction of the second. I'm stuck with how to actually convert the bottom 32 bits into a fraction…
davedavedave
  • 139
  • 1
  • 7
3
votes
1 answer

Optimizing Fixed-Point Sqrt

I made what I think is a good fixed-point square root algorithm: template typename enable_if>::type sqrt(FixedPoint f) { if (f.num == 0) return 0; //Reduce it to the 1/2 to 2…
user155698
  • 63
  • 4
3
votes
1 answer

implementing a modulus on fixed point type

so currently I'm helping develop a programming language, and we've reached the point where we have to implement a fixed point type using C++ as our backbone language to write this in. I am able to figure out how to add, subtract, multiply, divide,…
3
votes
1 answer

Binary fixed point multiplication

I am implementing a VHDL 8 bit fixed point multiplication module which returns an 8bit truncated number but I have a problem when I do multiplications by hand in order to test it. The problem arises when I want to multiply two negative numbers. I…
morcillo
  • 1,091
  • 5
  • 19
  • 51
3
votes
0 answers

Fixed point square root function wrong results for big numbers

Hello friends and enemies I have this square root function from a library called libfixmath which works great, however from 32767.0f and above it starts returning wrong and negative results. The numbers I need square root of are rather big, up to…
monkey
  • 31
  • 2
3
votes
1 answer

Fixed-point multiplication in a known range

I'm trying to multiply A*B in 16-bit fixed point, while keeping as much accuracy as possible. A is 16-bit in unsigned integer range, B is divided by 1000 and always between 0.001 and 9.999. It's been a while since I dealt with problems like that,…
viraptor
  • 33,322
  • 10
  • 107
  • 191
3
votes
1 answer

KissFFT Versus DSPIC - Rounding Errors

Trying to get the KissFFT fixed point implementation to line up with the DSPIC. The issue is that the fixed point implementation in Kiss is a true fixed point but the dspic does the multiplies and sums in a 40 bit register then shifts down to 16…
user2848810
  • 1,187
  • 1
  • 8
  • 12
3
votes
1 answer

Python decimal context for fixed point

I want to calculate with numbers having 3 places before and 2 places after decimal point (of course, 2 and 3 are configurable). I think it will be easiest to explain by examples: 0.01 and 999.99 are the lower and upper limit for positive numbers. Of…
Veky
  • 2,646
  • 1
  • 21
  • 30
3
votes
2 answers

Should I Stick to 32bit or 64bit Types for Fixed-Point Number Class?

I've been developing a game in C# which currently uses floating points for some calculations and arithmetic. This game will feature networking functionality and a basic replay system which keeps track of inputs and basic player actions over time. I…
TheYokai
  • 341
  • 5
  • 10
3
votes
1 answer

Overflow-aware implementation of a kalman filter

I'm trying to implement a kalman filter to obtain the orientation of an object, using an 3 axis accelerometer and a 3 axis gyroscope as sensors. Choosing the dynamic model for the predict phase of this filter is straight forward, it's: new_angle =…