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

Why perform multiplication in this way?

I've run into this function: static inline INT32 MPY48SR(INT16 o16, INT32 o32) { UINT32 Temp0; INT32 Temp1; // A1. get the lower 16 bits of the 32-bit param // A2. multiply them with the 16-bit param // A3. add 16384 (TODO:…
mpenkov
  • 21,621
  • 10
  • 84
  • 126
8
votes
6 answers

Python computing error

I’m using the API mpmath to compute the following sum Let us consider the serie u0, u1, u2 defined by: u0 = 3/2 = 1,5 u1 = 5/3 = 1,6666666… un+1 = 2003 - 6002/un + 4000/un un-1 The serie converges on 2, but with rounding problem it seems to…
7
votes
3 answers

Inverse sqrt for fixed point

I am looking for the best inverse square root algorithm for fixed point 16.16 numbers. The code below is what I have so far(but basically it takes the square root and divides by the original number, and I would like to get the inverse square root…
Jonathan
  • 489
  • 1
  • 7
  • 18
7
votes
4 answers

How to convert floating point algorithm to fixed point?

After reading quite a bit about fixed-point arithmetic I think I can say I've understood the basics, unfortunately I don't know yet how to convert routines that use sin/cos/sqrt or any other fp function. Consider this simple mcve: #include…
BPL
  • 9,632
  • 9
  • 59
  • 117
7
votes
2 answers

Algorithm for fixed-point multiplication

I'm trying to rescale a timestamp (fractional part of seconds only) from nanoseconds (units of 10^-9 seconds) to the lower half of an NTP timestamp (units of 2^-32 seconds). Effectively this means multiplying by 4.2949673. But I need to do it…
hobbs
  • 223,387
  • 19
  • 210
  • 288
7
votes
2 answers

An efficient method for calculating log base 2 of a number between 1 and 2

I am working on a fixed-point platform (floating-point arithmetic not supported). I represent any rational number q as the floor value of q * (1 << precision). I need an efficient method for calculating log base 2 of x, where 1 < x < 2. Here is what…
goodvibration
  • 5,980
  • 4
  • 28
  • 61
7
votes
4 answers

Convert a double to fixed decimal point in C++

I have a double variable in C++ and want to print it out to the screen as a fixed decimal point number. Basically I want to know how to write a function that takes a double and a number of decimal places and prints out the number to that number of…
tree-hacker
  • 5,351
  • 9
  • 38
  • 39
7
votes
1 answer

Matlab : how to perform fixed-point arithmetic without expanding underlying data type?

Google is silent on this issue. I'm currently implementing a numerical calculator on only 16-bit signed fixed point in Matlab. But arithmetic operation on 16bit fixed point causes expanding data type to the following >> a = int16(1.5 * 4) a = 6 >> T…
inherithandle
  • 2,614
  • 4
  • 31
  • 53
7
votes
2 answers

Signed & unsigned integer multiplication

In fixed point math I use a lot of 16bit signals and perform multiplication with 32bit intermediate results. For example: int16_t a = 16384; //-1.0q14 or 1.0*2^14 int16_t b = -24576; // -1.4q14 or 1.4*2^14 int16_t c; // result will be q14 c =…
phkahler
  • 5,687
  • 1
  • 23
  • 31
7
votes
1 answer

Fixed point type not multiplying correctly

I'm new to Ada, and have been trying out the fixed-point "delta" types. Specifically, I've created a 32-bit delta type range 0.0 .. 1.0. However, when I try to square certain values, I get a CONSTRAINT_ERROR. As far as I know, that should't…
ericmaht
  • 73
  • 3
7
votes
1 answer

IEEE floating point vs custom float performance

I'm working on a processor without a floating point unit so I have to use fixed or a custom floating point type for a user interface. What does the performance on say a multiply look like for these three types: IEEE Float (32) Custom 32 bit float…
Ryan Brown
  • 1,017
  • 1
  • 13
  • 34
6
votes
1 answer

Why does the standard provide both is_integer and is_exact?

std::numeric_limits provides 2 constants that are mutually exclusive: is_integer : "true for all integer arithmetic types T" is_exact: "true for all arithmetic types T that use exact representation" Is there the possibility of a non-exact integral…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
6
votes
2 answers

understanding Fixed point arithmetic

I am struggling with how to implement arithmetic on fixed-point numbers of different precision. I have read the paper by R. Yates, but I'm still lost. In what follows, I use Yates's notation, in which A(n,m) designates a signed fixed-point format…
py sqr
  • 63
  • 8
6
votes
2 answers

256 bit fixed point arithmetic, the future?

Just some silly musings, but if computers were able to efficiently calculate 256 bit arithmetic, say if they had a 256 bit architecture, I reckon we'd be able to do away with floating point. I also wonder, if there'd be any reason to progress past…
6
votes
2 answers

64-bit fixed-point multiplication error

I'm implementing a 64-bit fixed-point signed 31.32 numeric type in C#, based on long. So far so good for addition and substraction. Multiplication however has an annoying case I'm trying to solve. My current algorithm consist of splitting each…
Asik
  • 21,506
  • 6
  • 72
  • 131
1 2
3
34 35