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.

455 questions
64
votes
7 answers

storing money amounts in mysql

I want to store 3.50 into a mysql table. I have a float that I store it in, but it stores as 3.5, not 3.50. How can I get it to have the trailing zero?
David
  • 14,182
  • 34
  • 96
  • 150
56
votes
7 answers

C++ fixed point library?

I am looking for a free C++ fixed point library (Mainly for use with embedded devices, not for arbitrary precision math). Basically, the requirements are: No unnecessary runtime overhead: whatever can be done at compile time, should be done at…
uj2
  • 1,365
  • 2
  • 15
  • 15
53
votes
9 answers

What's the best way to do fixed-point math?

I need to speed up a program for the Nintendo DS which doesn't have an FPU, so I need to change floating-point math (which is emulated and slow) to fixed-point. How I started was I changed floats to ints and whenever I needed to convert them, I used…
Paige Ruten
  • 157,734
  • 36
  • 172
  • 191
50
votes
6 answers

Fixed point math in c#?

I was wondering if anyone here knows of any good resources for fixed point math in c#? I've seen things like this (http://2ddev.72dpiarmy.com/viewtopic.php?id=156) and this (What's the best way to do fixed-point math?), and a number of discussions…
x4000
  • 2,717
  • 3
  • 25
  • 24
33
votes
4 answers

Fixed Point Arithmetic in C Programming

I am trying to create an application that stores stock prices with high precision. Currently I am using a double to do so. To save up on memory can I use any other data type? I know this has something to do with fixed point arithmetic, but I can't…
RagHaven
  • 3,866
  • 16
  • 65
  • 103
30
votes
6 answers

How to use expr on float?

I know it's really stupid question, but I don't know how to do this in bash: 20 / 30 * 100 It should be 66.67 but expr is saying 0, because it doesn't support float. What command in Linux can replace expr and do this equalation?
lauriys
  • 4,134
  • 7
  • 30
  • 40
27
votes
4 answers

Fast fixed point pow, log, exp and sqrt

I've got a fixed point class (10.22) and I have a need of a pow, a sqrt, an exp and a log function. Alas I have no idea where to even start on this. Can anyone provide me with some links to useful articles or, better yet, provide me with some…
Goz
  • 58,120
  • 22
  • 114
  • 192
23
votes
6 answers

Converting floating point to fixed point

In C++, what's the generic way to convert any floating point value (float) to fixed point (int, 16:16 or 24:8)? EDIT: For clarification, fixed-point values have two parts to them: an integer part and a fractional part. The integer part can be…
CVertex
  • 17,451
  • 27
  • 88
  • 124
23
votes
7 answers

When to use Fixed Point these days

For intense number-crunching i'm considering using fixed point instead of floating point. Of course it'll matter how many bytes the fixed point type is in size, on what CPU it'll be running on, if i can use (for Intel) the MMX or SSE or whatever…
DarenW
  • 15,697
  • 7
  • 59
  • 96
22
votes
7 answers

What do you use for fixed point representation in C++?

I'm looking for a fixed-point standard to use for financial data, do you know any that is worth trying? Do you have any experience on the performance of that hand-made fixed-point classes?
Edwin Jarvis
  • 5,430
  • 6
  • 33
  • 41
17
votes
2 answers

Fixed point processing: what is the difference between uint16_t and uint_fast16_t?

I have a 16 bit fixed point processor and I want to do fixed point processing with it. I'm looking for the correct datatype to use for unsigned 16 bit ints.. My question is: what is the difference between a uint16_t and uint_fast16_t? (These are…
O_O
  • 4,017
  • 15
  • 46
  • 66
17
votes
5 answers

Oracle Floats vs Number

I'm seeing conflicting references in Oracles documentation. Is there any difference between how decimals are stored in a FLOAT and a NUMBER types in the database? As I recall from C, et al, a float has accuracy limitations that an int doesn't have.…
BIBD
  • 14,299
  • 24
  • 78
  • 130
16
votes
1 answer

Emulating fixed precision in python

For a university course in numerical analysis we are transitioning from Maple to a combination of Numpy and Sympy for various illustrations of the course material. This is because the students already learn Python the semester before. One of the…
16
votes
2 answers

How to do floating point calculations with integers

I have a coprocessor attached to the main processor. Some floating point calculations needs to be done in the coprocessor, but it does not support hardware floating point instructions, and emulation is too slow. Now one way is to have the main…
MetallicPriest
  • 25,675
  • 38
  • 166
  • 299
15
votes
3 answers

How to convert packed integer (16.16) fixed-point to float?

How to convert a "32-bit signed fixed-point number (16.16)" to a float? Is (fixed >> 16) + (fixed & 0xffff) / 65536.0 ok? What about -2.5? And -0.5? Or is fixed / 65536.0 the right way? (PS: How does signed fixed-point "-0.5" looks like in memory…
Ecir Hana
  • 9,122
  • 13
  • 58
  • 105
1
2 3
30 31