Universal Numbers Library C++ API
sw::universal -- header-only custom arithmetic types (posit, cfloat, lns, fixpnt, dd/qd, and more)
Loading...
Searching...
No Matches
sw::universal::teju Namespace Reference

Namespaces

namespace  detail

Classes

struct  decimal_fp

Functions

decimal_fp to_decimal (uint64_t mantissa, int exponent, unsigned mantissa_width)
 Convert a binary floating-point value to its shortest decimal representation.
decimal_fp float_to_decimal (float value)
 Convenience: convert a native float to shortest decimal.
decimal_fp double_to_decimal (double value)
 Convenience: convert a native double to shortest decimal.

Function Documentation

◆ double_to_decimal()

decimal_fp sw::universal::teju::double_to_decimal ( double value)
inline

Convenience: convert a native double to shortest decimal.

Preconditions: value must be finite, positive, and non-zero. Zero, NaN, infinity, and negative values return {0, 0}.

◆ float_to_decimal()

decimal_fp sw::universal::teju::float_to_decimal ( float value)
inline

Convenience: convert a native float to shortest decimal.

Preconditions: value must be finite, positive, and non-zero. Zero, NaN, infinity, and negative values return {0, 0}.

◆ to_decimal()

decimal_fp sw::universal::teju::to_decimal ( uint64_t mantissa,
int exponent,
unsigned mantissa_width )
inline

Convert a binary floating-point value to its shortest decimal representation.

Parameters
mantissaFull binary significand (with implicit 1 bit set for normals)
exponentBinary exponent such that value = mantissa * 2^exponent
mantissa_widthTotal number of significand bits (including hidden bit)
Returns
decimal_fp with the shortest decimal mantissa and exponent

Preconditions: mantissa > 0 (value must be finite and positive) The caller handles sign, zero, NaN, and infinity.