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

How to name functions to extract parts of a decimal number?

I am writing a class for handling decimal numbers, e.g. "123.456". I want one function for extracting the digits before the decimal point (123), and one function to extract the digits after the decimal point (0.456). My question is not how to do the…
Johan Kotlinski
  • 25,185
  • 9
  • 78
  • 101
3
votes
2 answers

How to divide a fixed point number by a small float number?

I need to divide a set of 5U11 numbers by 6.02 and would prefer to do this without casting to float and back. 5U11 means a 16-bit unsigned number, with the 11 least significant bits representing fractional part. How should I represent 6.02 and what…
Vorac
  • 8,726
  • 11
  • 58
  • 101
3
votes
0 answers

libfixmath's atan2 seems to produce invalid results - any ideas, suggestions or alternatives?

I want to do fixed point math in C++, so I looked for a suitable library. libfixmath has been suggested here a couple of times, but I have difficulties with the atan2 function it provides. My test code calculates sine and cosine of an angle and then…
Christoph
  • 1,040
  • 3
  • 14
  • 29
3
votes
2 answers

Compiling *.vhdl into a library, using Altera Quartus II

I am trying to use 'Floating point and Fixed point package' as a part of my filter design in VHDL. I am using Altera Quartus II as the development environment. I downloaded the file package from the website: http://www.vhdl.org/fphdl/, now available…
ElectroJunkie
  • 301
  • 5
  • 16
3
votes
0 answers

Complex numbers: fast cartesian to polar conversion

I'm looking for a fast way to turn an array of complex numbers into polar representation. E.g, given a complex number X I want to turn it into polar representation like this: Q.phase = atan2 (X.imag / X.real); Q.magniude = sqrt (X.imag *…
Nils Pipenbrinck
  • 83,631
  • 31
  • 151
  • 221
3
votes
3 answers

Unsafe pointer manipulation

I'm trying to write a CPU emulator in C#. The machine's object looks like this: class Machine { short a,b,c,d; //these are registers. short[] ram=new short[0x10000]; //RAM organised as 65536 16-bit words public void tick() { ... }…
Matthew Sainsbury
  • 1,470
  • 3
  • 18
  • 42
3
votes
2 answers

Square root of s15.16 fixed point number in Java

I want to write a function to calculate the square root of a s15.16 fixed point number. I know its a signed number with 15 digit int and 16 digit fraction. Is there anyway to do it without any libraries? Any other languages is fine too.
AliBZ
  • 4,039
  • 12
  • 45
  • 67
3
votes
2 answers

32-bit fractional multiplication with cross-multiplication method (no 64-bit intermediate result)

I am programming a fixed-point speech enhancement algorithm on a 16-bit processor. At some point I need to do 32-bit fractional multiplication. I have read other posts about doing 32-bit multiplication byte by byte and I see why this works for Q0.31…
EliasK
  • 31
  • 4
3
votes
4 answers

Avoiding floating point arithmetic

I wrote a small software synth for the iPhone. To further tune performance I measured my application with Shark and found that I am losing a lot of time in float/SInt16 conversions. So I rewrote some parts to get around the conversions by…
3
votes
2 answers

Using two uint's to represent a double, then multiply?

I'm working with CUDA (GPGPU programming) for some research and the innate Double Precision performance suffers compares to the Single Precision performance (by a factor of 24!), due to a new hardware architecture. I've decided to try and use two…
JohnDoe
  • 77
  • 6
3
votes
3 answers

How to determine the feasibility of using fixed-point numbers on a given (game) project?

I have considered posting this question on GameDev since my case relates to a game project, but I figured this would be more suited for a broader programming SE. Please let me know if this question would be better posted there after all. From my…
Vexille
  • 153
  • 4
3
votes
2 answers

How do I force Python to keep an integer out of scientific notation

I am trying to write a method in Python 3.2 that encrypts a phrase and then decrypts it. The problem is that the numbers are so big that when Python does math with them it immediately converts it into scientific notation. Since my code requires all…
Dan G.
  • 982
  • 1
  • 8
  • 20
3
votes
4 answers

Benefits of using fixed-point arithmetic in C++ for devices without FPU

I would like to optimize my C++ code for an ARM device, which lacks a floating point unit. Most of my functions use floats, and I am considering changing them to fixed-point. Are there real benefits in the case of ARM devices, or are compilers smart…
Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
2
votes
1 answer

Converting a binary sequence read from a file into a fixed point number

I am trying to parse a file which has ITCH messages in it: http://www.nasdaqtrader.com/Trader.aspx?id=DPSpecs_USEquities#TVITCH¬ http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/NQTV-ITCH-V4_1.pdf¬ Each price is…
2
votes
1 answer

Fixed point in Matlab

Can someone please explain this? As I understand it provides less precision..Is it a speed-up that one wishes to get by using it? When is it good to use? Should I use it in Matlab Coder?
Michael Ward
  • 213
  • 5
  • 12