Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer type with floating point semantics for C or D

Tags:

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: Overflow produces infinity (-infinity for signed underflow) rather than wrapping around or having undefined behavior, undefined operations produce NaN, etc.

In essence, a version of floating point where the distribution of presentable numbers falls evenly on the number line, instead of conglomerating around 0.

In addition, all operations should be deterministic; any given two's complement 32-bit architecture should produce the exact same result for the same computation, regardless of its implementation (whereas floating point may, and often will, produce slightly differing results).

Finally, performance is a concern, which has me worried about potential "bignum" (arbitrary-precision) solutions.

See also: Fixed-point and saturation arithmetic.