Skip to content

ieeeBinaryFromDecimal

ieeeBinaryFromDecimal(decimal, format): IeeeBinary<bigint>

Defined in: packages/math-numbers/src/ieee754/binary/ieee-binary-from-decimal.ts:23

The value of decimal in format, correctly rounded.

Going through a JS number first would cap the result at binary64 whatever the target format, so 1.0000000000000000000001 would land on exactly 1 in binary128. This scales the coefficient in integer arithmetic instead and hands the division remainder to the rounder as a sticky bit, so the result is the same one a correctly-rounded decimal-to-binary conversion gives.

Time complexity: O(M(d)) for a d-digit coefficient, dominated by the bigint multiply and divide.

Decimal

IeeeFormat

IeeeBinary<bigint>

±0 for a zero coefficient, ±∞ past the format’s range.