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

Fixed-Point-Math - Is the conversion from float safe to always yield the same result?

I'm using libfixmath for a simulation the needs to take place on two devices (iOS / Android) at the same time and be perfectly accurate. The simulation needs to be fed with some initial float parameters. I'm wondering, if it's safe to use floats and…
keyboard
  • 2,137
  • 1
  • 20
  • 32
4
votes
3 answers

Floating Point Algorithms in C

I am thinking recently on how floating point math works on computers and is hard for me understand all the tecnicals details behind the formulas. I would need to understand the basics of addition, subtraction, multiplication, division and remainder.…
4
votes
1 answer

Fixed Point Perlin Noise returns sum of input points as output

I have taken the fixed-point perlin-noise implementation from: http://mrl.nyu.edu/~perlin/noise/INoise.java and modified it slightly so it compiles under c#. In this version 1.0 is represented by 2^16. When I pass in input coordinates (int x, int…
ShaunAU
  • 41
  • 4
4
votes
1 answer

Fastest way to multiply two 64-bit ints to 128-bit then >> to 64-bit?

I need to multiply two signed 64-bit integers a and b together, then shift the (128-bit) result to a signed 64-bit integer. What's the fastest way to do that? My 64-bit integers actually represent fixed-point numbers with fmt fractional bits. fmt is…
Michel Rouzic
  • 1,013
  • 1
  • 9
  • 22
4
votes
4 answers

Removing slow int64 division from fixed point atan2() approximation

I made a function to compute a fixed-point approximation of atan2(y, x). The problem is that of the ~83 cycles it takes to run the whole function, 70 cycles (compiling with gcc 4.9.1 mingw-w64 -O3 on an AMD FX-6100) are taken entirely by a simple…
Michel Rouzic
  • 1,013
  • 1
  • 9
  • 22
4
votes
3 answers

Range analysis of floating point values?

I have an image processing program which uses floating point calculations. However, I need to port it to a processor which does not have floating point support in it. So, I have to change the program to use fixed point calculations. For that I need…
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
4
votes
3 answers

Notation for fixed point representation

I'm looking for a commonly understandable notation to define a fixed point number representation. The notation should be able to define both a power-of-two factor (using fractional bits) and a generic factor (sometimes I'm forced to use this, though…
omegatre
  • 178
  • 7
4
votes
1 answer

Fastest way to convert 16.16 fixed point to 32 bit float in c/c++ on x86?

Most people seem to want to go the other way. I'm wondering if there is a fast way to convert fixed point to floating point, ideally using SSE2. Either straight C or C++ or even asm would be fine.
user51511
4
votes
2 answers

How to read fixed point numbers in python

I would like to read an 8 bit number that comes in a 2's complement fix8_7 (8 bit number and the binary point is in the 7 bit). How can I do this in Python?
maverick88
  • 41
  • 1
  • 7
4
votes
2 answers

Behaviour of Matlab fixed-point numbers with 1-bit

I noticed a funny behaviour with Matlab-FI numbers. It occurs only with 1-bit, signed numbers (a datatype that does not make a lot of sense in practice). I'm aware that multiplying a double with a fi is not a good practice and the behaviour may even…
mbschenkel
  • 1,865
  • 1
  • 18
  • 40
4
votes
1 answer

JavaScript: represent float as product of integer and power of ten

For instance, I have float 1.1111111111 and need to get 11111111111 and 10. I want to avoid functions, which may change part after point as I need it to show metric prefixes. It may look simple with strings, I am just not sure if it is a proper way…
ISE
  • 436
  • 2
  • 9
  • 21
4
votes
3 answers

fixedpoint implementation of function bool isnan( … ) in C++

i am doing fixed point implementation in c++ and i am trying to define “not-a-number” and support a function bool isnan( … ) which returns true if the number is not-a-number and false otherwise. can someone one give me some ideas of how to define…
Dev
  • 153
  • 1
  • 1
  • 6
4
votes
1 answer

fixed point multiplication without 64 bit temporary

Hi I'm implementing some fixed point math stuff for embedded systems and I'm trying to do the multiplication of two 16.16 fixed point numbers without creating a 64bit temporary. So far here is the code I came up with that generates the least…
PgrAm
  • 671
  • 2
  • 7
  • 19
4
votes
1 answer

Fixed-point modulo edge cases

I'm implementing a Q31.32 fixed-point numeric type based on System.Int64 in C#. Right now I'm trying to get the modulo operation correctly (%). All implementations of fixed-point arithmetic I've seen define Qm.n modulo simply in terms of integer…
Asik
  • 21,506
  • 6
  • 72
  • 131
4
votes
3 answers

How do you multiply two fixed point numbers?

I am currently trying to figure out how to multiply two numbers in fixed point representation. Say my number representation is as follows: [SIGN][2^0].[2^-1][2^-2]..[2^-14] In my case, the number 10.01000000000000 = -0.25. How would I for example…
fouadalnoor
  • 197
  • 2
  • 5
  • 14