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

initialize a variable statically (at compile time)

1) I've got many constants in my C algo. 2) my code works both in floating-point and fixed-point. Right now, these constants are initialized by a function, float2fixed, whereby in floating-point it does nothing, while in fixed-point, it finds their…
3
votes
2 answers

Fixed-point unsigned division in C

I need an algorithm to do unsigned fixed-point division in C. I can use at most 32-bit words. I want to minimize the number of bits needed to represent the integer part while being able to use numbers in the range [0..15]. So apparently the minimum…
Kei Nivky
  • 367
  • 2
  • 5
  • 12
3
votes
1 answer

How to subdivide integer hash into ranges

I have unsigned 64bit number, representing mantissa, or fraction (which represent range from [0..1), where 0.0 maps to 0 and 0xffffff.. maps to a number "just before 1.0") Now i want to split this range into equal buckets - and to answer - given…
xakepp35
  • 2,878
  • 7
  • 26
  • 54
3
votes
1 answer

Normalizing a vector with great accuracy and big numbers using fixed-point arithmetic

Why do I need this? I'm creating a game about space. For a space game to work it'll need big and accurate numbers. Floating-point numbers are not really great for such application because if you get pretty far away in the world the precision will be…
Mark
  • 182
  • 1
  • 9
3
votes
1 answer

C: Representing a fraction without floating points

I'm writing some code for an embedded system (MSP430) without hardware floating point support. Unfortunately, I will need to work with fractions in my code as I'm doing ranging, and a short-range sensor with a precision of 1m isn't a very good…
HFOrangefish
  • 267
  • 1
  • 10
3
votes
2 answers

Trouble in implementing fixed-point numbers in C

I am trying to make a small fixed-point math library. My fixed point numbers are 32-bit, with 16 bits each for the integral and fractional parts. The trouble comes with adding fixed-point numbers and then seeing the resulting value. The function…
Caspian Ahlberg
  • 934
  • 10
  • 19
3
votes
1 answer

Calculating price using Web3py and Uniswap pair smart contracts: How to deal with fixed point numbers?

I'm trying to calculate the price of a token in Uniswap using web3.py and a Uniswap pair contract, but I must be doing something wrong with the math. Example: I would like to calculate the price of one ETH denominated in USDC. I first connect to the…
Karim
  • 31
  • 1
  • 2
3
votes
2 answers

What's the difference between fixed point math and integer math

Maybe this is a red herring but I'm trying to understand what (if any) differences exist between integer math and math on some other fixed point number system. Is there additional cost to operations on a fixed point number where 2^0 isn't bit…
spizzak
  • 1,087
  • 1
  • 11
  • 17
3
votes
1 answer

Unsigned fixed point 0.28 format

I found in a stepper driver datasheet L6472 the following description: What is the "unsigned fixed point 0.28 format"? I found information about the fixed point format itself, but what does the 0.28 mean? Is there an easy implementation for this…
Corono
  • 35
  • 5
3
votes
3 answers

implementing a hash table-like data structure with floating point keys where values within a tolerance are binned together

I need an associative data structure with floating point keys in which keys with nearly equal values are binned together. I'm working in C++ but language doesnt really matter. Basically my current strategy is to only handle single precision…
jwezorek
  • 8,592
  • 1
  • 29
  • 46
3
votes
2 answers

c - understanding fixed point bit model

So I'm learning about binary values and I'm trying to understand how to calculate the negative version of a number using the fixed point bit model. In my textbook it says 000111.01 = 7.25 which I understand. But it's telling me -7.25 is 111000.11…
Grayish
  • 187
  • 1
  • 10
3
votes
2 answers

How to correctly print a 2.30 fixed point variable

I'm obtaining a DFT using a cortex-M3. I'm calculating the magnitude using the CMSIS DSP function arm_cmplx_mag_q31. The documentation says that it returns the result in the format 2.30 (which I assume is 2 bits for the integer and 30 for the…
DCrown
  • 57
  • 7
3
votes
1 answer

Exactly how is fixed point more accurate than floating point

I (think) I understand the both fixed and floating point representations of fractional numbers in binary. However, I often see fixed point described as more accurate with less range, and floating point described as less accurate with more range.…
KiwiNoob
  • 39
  • 2
3
votes
3 answers

How to use chisel dsptools with floats

I need to convert a Float32 into a Chisel FixedPoint, perform some computation and convert back FixedPoint to Float32. For example, I need the following: val a = 3.1F val b = 2.2F val res = a * b // REPL returns res: Float 6.82 Now, I do…
Tampler
  • 385
  • 1
  • 9
3
votes
3 answers

Json in C++: Parse a number as a string to avoid floating-point inaccuracy

I'm dealing with a cryptocurrency RPC and receiving json data as follows: { ... "amount": 1.34000000, "confirmations": 230016, "spendable": true, "solvable": true ... } Using Jsoncpp library or json11 gets the number parsed to a double.…
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189