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

C++ library for integer trigonometry, speed optimized with optional approximations?

I've reached the point in a project where it makes more sense to start building some support classes for vectors and misc trigonometry than keep using ad-hoc functions. I expect there to be many C++ libraries for this, but I don't want to sacrifice…
porgarmingduod
  • 7,668
  • 10
  • 50
  • 83
14
votes
5 answers

How do I convert a floating point C code to fixed point?

I have a C code which uses doubles. I want to be able to run the code on a DSP (TMS320). But the DSP doesn't support doubles, only fixed-point numbers. What is the best way to convert the code into fixed-point? Is there a good C library for…
snakile
  • 52,936
  • 62
  • 169
  • 241
13
votes
3 answers

Why aren't fixed-point types included in C99?

Thankfully, the complex type modifier was introduced into C99 standard. What I don't understand is why it was decided to omit support for fixed point arithmetic (specifically, support fractional types like 1.15 {signed} or 0.32 {unsigned}) where…
ysap
  • 7,723
  • 7
  • 59
  • 122
13
votes
4 answers

How to improve fixed point square-root for small values

I am using Anthony Williams' fixed point library described in the Dr Dobb's article "Optimizing Math-Intensive Applications with Fixed-Point Arithmetic" to calculate the distance between two geographical points using the Rhumb Line method. This…
Clifford
  • 88,407
  • 13
  • 85
  • 165
13
votes
3 answers

.NET - Why is there no fixed point numeric data type in C#?

It seems like there would be a ton of uses for a fixed point data type. Why is there not one in .NET? Note: I understand we can create our own classes/structs to suit our fixed point purposes and needs. That's not my question. I want to know WHY MS…
richard
  • 12,263
  • 23
  • 95
  • 151
13
votes
1 answer

BigDecimal.add strange behavior

Method BigDecimal.add takes a long time when one argument has a big exponent (9 digits), and the second has an exponent with the different length. I've waited for more than 5 minutes, and it was still going on and on. Here's code: @Test public void…
VMN
  • 275
  • 2
  • 13
13
votes
6 answers

Invert 4x4 matrix - Numerical most stable solution needed

I want to invert a 4x4 matrix. My numbers are stored in fixed-point format (1.15.16 to be exact). With floating-point arithmetic I usually just build the adjoint matrix and divide by the determinant (e.g. brute force the solution). That worked for…
12
votes
3 answers

How to optimize a simple numeric type wrapper class in C++?

I am trying to implement a fixed-point class in C++, but I face problems with performance. I have reduced the problem to a simple wrapper of the float type and it is still slow. My question is - why is the compiler unable optimize it fully? The…
Michal Czardybon
  • 2,795
  • 4
  • 28
  • 40
12
votes
2 answers

How can I perform 64-bit division with a 32-bit divide instruction?

This is (AFAIK) a specific question within this general topic. Here's the situation: I have an embedded system (a video game console) based on a 32-bit RISC microcontroller (a variant of NEC's V810). I want to write a fixed-point math library. I…
12
votes
3 answers

Will fixed-point arithmetic be worth my trouble?

I'm working on a fluid dynamics Navier-Stokes solver that should run in real time. Hence, performance is important. Right now, I'm looking at a number of tight loops that each account for a significant fraction of the execution time: there is no…
Thomas
  • 174,939
  • 50
  • 355
  • 478
12
votes
2 answers

How to make use of the GCC fixed-point types extension on ARM Cortex-M?

I am using a ARM Cortex-M3, and a Cortex-M4. I want to make use of GCC's fixed-point type extension. I am using the summon-arm-toolchain. The following line of code _Fract f = 0.1; throws the following compile error: error: fixed-point types not…
user1069152
  • 495
  • 5
  • 14
11
votes
2 answers

C++ compile-time bignum library

Is there any compile-time library (template metaprogramming) for arbitrary-precision arithmetic in C++? I need this to help with fixed-point arithmetic and binary scaling in my program for AVR microcontrollers. For example, when two numbers each…
9
votes
1 answer

Fixed point multiplication of negative numbers

I have the following method to multiply two 32 bit numbers in fixed point 19.13 format. But I think there is a problem with this method: 1.5f is rounded up to 2.0f, while -1.5f is rounded up to -1.0f. It seems to me that -1.5 should be rounded down…
Jacko
  • 12,665
  • 18
  • 75
  • 126
9
votes
1 answer

Are all C++ fixed-point operations deterministic?

I'm writing a small RTS engine in C++ and want to use lockstep synchronisation. As floating point determinism is something I can't even hope to achieve, I have to use fixed point math. How deterministically (over different compilers and cpus) are…
lines
  • 141
  • 5
9
votes
4 answers

Integer type with floating point semantics for C or D

I'm looking for an existing implementation for C or D, or advice in implementing, signed and/or unsigned integer types with floating point semantics. That is to say, an integer type that behaves as floating point types do when doing arithmetic:…
Core Xii
  • 6,270
  • 4
  • 31
  • 42
1
2
3
34 35