@nberlette/math 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +889 -0
- package/cjs/abs.d.ts +14 -0
- package/cjs/abs.d.ts.map +1 -0
- package/cjs/abs.js +22 -0
- package/cjs/abs.js.map +1 -0
- package/cjs/acos.d.ts +17 -0
- package/cjs/acos.d.ts.map +1 -0
- package/cjs/acos.js +27 -0
- package/cjs/acos.js.map +1 -0
- package/cjs/acosh.d.ts +11 -0
- package/cjs/acosh.d.ts.map +1 -0
- package/cjs/acosh.js +35 -0
- package/cjs/acosh.js.map +1 -0
- package/cjs/asin.d.ts +11 -0
- package/cjs/asin.d.ts.map +1 -0
- package/cjs/asin.js +28 -0
- package/cjs/asin.js.map +1 -0
- package/cjs/asinh.d.ts +9 -0
- package/cjs/asinh.d.ts.map +1 -0
- package/cjs/asinh.js +26 -0
- package/cjs/asinh.js.map +1 -0
- package/cjs/atan.d.ts +11 -0
- package/cjs/atan.d.ts.map +1 -0
- package/cjs/atan.js +65 -0
- package/cjs/atan.js.map +1 -0
- package/cjs/atan2.d.ts +12 -0
- package/cjs/atan2.d.ts.map +1 -0
- package/cjs/atan2.js +70 -0
- package/cjs/atan2.js.map +1 -0
- package/cjs/atanh.d.ts +11 -0
- package/cjs/atanh.d.ts.map +1 -0
- package/cjs/atanh.js +32 -0
- package/cjs/atanh.js.map +1 -0
- package/cjs/cbrt.d.ts +9 -0
- package/cjs/cbrt.d.ts.map +1 -0
- package/cjs/cbrt.js +26 -0
- package/cjs/cbrt.js.map +1 -0
- package/cjs/ceil.d.ts +15 -0
- package/cjs/ceil.d.ts.map +1 -0
- package/cjs/ceil.js +34 -0
- package/cjs/ceil.js.map +1 -0
- package/cjs/clamp.d.ts +15 -0
- package/cjs/clamp.d.ts.map +1 -0
- package/cjs/clamp.js +32 -0
- package/cjs/clamp.js.map +1 -0
- package/cjs/clz32.d.ts +20 -0
- package/cjs/clz32.d.ts.map +1 -0
- package/cjs/clz32.js +48 -0
- package/cjs/clz32.js.map +1 -0
- package/cjs/constants/e.d.ts +17 -0
- package/cjs/constants/e.d.ts.map +1 -0
- package/cjs/constants/e.js +19 -0
- package/cjs/constants/e.js.map +1 -0
- package/cjs/constants/epsilon.d.ts +24 -0
- package/cjs/constants/epsilon.d.ts.map +1 -0
- package/cjs/constants/epsilon.js +26 -0
- package/cjs/constants/epsilon.js.map +1 -0
- package/cjs/constants/index.d.ts +23 -0
- package/cjs/constants/index.d.ts.map +1 -0
- package/cjs/constants/index.js +39 -0
- package/cjs/constants/index.js.map +1 -0
- package/cjs/constants/infinity.d.ts +3 -0
- package/cjs/constants/infinity.d.ts.map +1 -0
- package/cjs/constants/infinity.js +19 -0
- package/cjs/constants/infinity.js.map +1 -0
- package/cjs/constants/ln10.d.ts +10 -0
- package/cjs/constants/ln10.d.ts.map +1 -0
- package/cjs/constants/ln10.js +12 -0
- package/cjs/constants/ln10.js.map +1 -0
- package/cjs/constants/ln2.d.ts +10 -0
- package/cjs/constants/ln2.d.ts.map +1 -0
- package/cjs/constants/ln2.js +12 -0
- package/cjs/constants/ln2.js.map +1 -0
- package/cjs/constants/log10e.d.ts +10 -0
- package/cjs/constants/log10e.d.ts.map +1 -0
- package/cjs/constants/log10e.js +12 -0
- package/cjs/constants/log10e.js.map +1 -0
- package/cjs/constants/log2e.d.ts +10 -0
- package/cjs/constants/log2e.d.ts.map +1 -0
- package/cjs/constants/log2e.js +12 -0
- package/cjs/constants/log2e.js.map +1 -0
- package/cjs/constants/max_safe_integer.d.ts +11 -0
- package/cjs/constants/max_safe_integer.d.ts.map +1 -0
- package/cjs/constants/max_safe_integer.js +13 -0
- package/cjs/constants/max_safe_integer.js.map +1 -0
- package/cjs/constants/max_value.d.ts +10 -0
- package/cjs/constants/max_value.d.ts.map +1 -0
- package/cjs/constants/max_value.js +12 -0
- package/cjs/constants/max_value.js.map +1 -0
- package/cjs/constants/min_safe_integer.d.ts +12 -0
- package/cjs/constants/min_safe_integer.d.ts.map +1 -0
- package/cjs/constants/min_safe_integer.js +14 -0
- package/cjs/constants/min_safe_integer.js.map +1 -0
- package/cjs/constants/min_value.d.ts +10 -0
- package/cjs/constants/min_value.d.ts.map +1 -0
- package/cjs/constants/min_value.js +12 -0
- package/cjs/constants/min_value.js.map +1 -0
- package/cjs/constants/nan.d.ts +47 -0
- package/cjs/constants/nan.d.ts.map +1 -0
- package/cjs/constants/nan.js +30 -0
- package/cjs/constants/nan.js.map +1 -0
- package/cjs/constants/negative_infinity.d.ts +28 -0
- package/cjs/constants/negative_infinity.d.ts.map +1 -0
- package/cjs/constants/negative_infinity.js +15 -0
- package/cjs/constants/negative_infinity.js.map +1 -0
- package/cjs/constants/negative_zero.d.ts +31 -0
- package/cjs/constants/negative_zero.d.ts.map +1 -0
- package/cjs/constants/negative_zero.js +21 -0
- package/cjs/constants/negative_zero.js.map +1 -0
- package/cjs/constants/pi.d.ts +10 -0
- package/cjs/constants/pi.d.ts.map +1 -0
- package/cjs/constants/pi.js +12 -0
- package/cjs/constants/pi.js.map +1 -0
- package/cjs/constants/positive_infinity.d.ts +29 -0
- package/cjs/constants/positive_infinity.d.ts.map +1 -0
- package/cjs/constants/positive_infinity.js +16 -0
- package/cjs/constants/positive_infinity.js.map +1 -0
- package/cjs/constants/positive_zero.d.ts +38 -0
- package/cjs/constants/positive_zero.d.ts.map +1 -0
- package/cjs/constants/positive_zero.js +36 -0
- package/cjs/constants/positive_zero.js.map +1 -0
- package/cjs/constants/sqrt1_2.d.ts +9 -0
- package/cjs/constants/sqrt1_2.d.ts.map +1 -0
- package/cjs/constants/sqrt1_2.js +11 -0
- package/cjs/constants/sqrt1_2.js.map +1 -0
- package/cjs/constants/sqrt2.d.ts +9 -0
- package/cjs/constants/sqrt2.d.ts.map +1 -0
- package/cjs/constants/sqrt2.js +11 -0
- package/cjs/constants/sqrt2.js.map +1 -0
- package/cjs/cos.d.ts +10 -0
- package/cjs/cos.d.ts.map +1 -0
- package/cjs/cos.js +32 -0
- package/cjs/cos.js.map +1 -0
- package/cjs/cosh.d.ts +10 -0
- package/cjs/cosh.d.ts.map +1 -0
- package/cjs/cosh.js +21 -0
- package/cjs/cosh.js.map +1 -0
- package/cjs/exp.d.ts +20 -0
- package/cjs/exp.d.ts.map +1 -0
- package/cjs/exp.js +48 -0
- package/cjs/exp.js.map +1 -0
- package/cjs/expm1.d.ts +11 -0
- package/cjs/expm1.d.ts.map +1 -0
- package/cjs/expm1.js +38 -0
- package/cjs/expm1.js.map +1 -0
- package/cjs/f16round.d.ts +24 -0
- package/cjs/f16round.d.ts.map +1 -0
- package/cjs/f16round.js +42 -0
- package/cjs/f16round.js.map +1 -0
- package/cjs/float16/constants.d.ts +97 -0
- package/cjs/float16/constants.d.ts.map +1 -0
- package/cjs/float16/constants.js +99 -0
- package/cjs/float16/constants.js.map +1 -0
- package/cjs/float16/decode.d.ts +40 -0
- package/cjs/float16/decode.d.ts.map +1 -0
- package/cjs/float16/decode.js +67 -0
- package/cjs/float16/decode.js.map +1 -0
- package/cjs/float16/encode.d.ts +67 -0
- package/cjs/float16/encode.d.ts.map +1 -0
- package/cjs/float16/encode.js +77 -0
- package/cjs/float16/encode.js.map +1 -0
- package/cjs/float16/guards.d.ts +22 -0
- package/cjs/float16/guards.d.ts.map +1 -0
- package/cjs/float16/guards.js +15 -0
- package/cjs/float16/guards.js.map +1 -0
- package/cjs/float16/index.d.ts +11 -0
- package/cjs/float16/index.d.ts.map +1 -0
- package/cjs/float16/index.js +27 -0
- package/cjs/float16/index.js.map +1 -0
- package/cjs/float16/round.d.ts +25 -0
- package/cjs/float16/round.d.ts.map +1 -0
- package/cjs/float16/round.js +46 -0
- package/cjs/float16/round.js.map +1 -0
- package/cjs/float32/constants.d.ts +96 -0
- package/cjs/float32/constants.d.ts.map +1 -0
- package/cjs/float32/constants.js +98 -0
- package/cjs/float32/constants.js.map +1 -0
- package/cjs/float32/decode.d.ts +38 -0
- package/cjs/float32/decode.d.ts.map +1 -0
- package/cjs/float32/decode.js +70 -0
- package/cjs/float32/decode.js.map +1 -0
- package/cjs/float32/encode.d.ts +50 -0
- package/cjs/float32/encode.d.ts.map +1 -0
- package/cjs/float32/encode.js +77 -0
- package/cjs/float32/encode.js.map +1 -0
- package/cjs/float32/guards.d.ts +37 -0
- package/cjs/float32/guards.d.ts.map +1 -0
- package/cjs/float32/guards.js +20 -0
- package/cjs/float32/guards.js.map +1 -0
- package/cjs/float32/index.d.ts +11 -0
- package/cjs/float32/index.d.ts.map +1 -0
- package/cjs/float32/index.js +27 -0
- package/cjs/float32/index.js.map +1 -0
- package/cjs/float32/round.d.ts +23 -0
- package/cjs/float32/round.d.ts.map +1 -0
- package/cjs/float32/round.js +36 -0
- package/cjs/float32/round.js.map +1 -0
- package/cjs/floor.d.ts +10 -0
- package/cjs/floor.d.ts.map +1 -0
- package/cjs/floor.js +32 -0
- package/cjs/floor.js.map +1 -0
- package/cjs/fround.d.ts +23 -0
- package/cjs/fround.d.ts.map +1 -0
- package/cjs/fround.js +35 -0
- package/cjs/fround.js.map +1 -0
- package/cjs/guards/finite.d.ts +23 -0
- package/cjs/guards/finite.d.ts.map +1 -0
- package/cjs/guards/finite.js +21 -0
- package/cjs/guards/finite.js.map +1 -0
- package/cjs/guards/index.d.ts +50 -0
- package/cjs/guards/index.d.ts.map +1 -0
- package/cjs/guards/index.js +66 -0
- package/cjs/guards/index.js.map +1 -0
- package/cjs/guards/infinity.d.ts +3 -0
- package/cjs/guards/infinity.d.ts.map +1 -0
- package/cjs/guards/infinity.js +19 -0
- package/cjs/guards/infinity.js.map +1 -0
- package/cjs/guards/integer.d.ts +47 -0
- package/cjs/guards/integer.d.ts.map +1 -0
- package/cjs/guards/integer.js +23 -0
- package/cjs/guards/integer.js.map +1 -0
- package/cjs/guards/nan.d.ts +61 -0
- package/cjs/guards/nan.d.ts.map +1 -0
- package/cjs/guards/nan.js +68 -0
- package/cjs/guards/nan.js.map +1 -0
- package/cjs/guards/negative_infinity.d.ts +19 -0
- package/cjs/guards/negative_infinity.d.ts.map +1 -0
- package/cjs/guards/negative_infinity.js +25 -0
- package/cjs/guards/negative_infinity.js.map +1 -0
- package/cjs/guards/negative_zero.d.ts +12 -0
- package/cjs/guards/negative_zero.d.ts.map +1 -0
- package/cjs/guards/negative_zero.js +24 -0
- package/cjs/guards/negative_zero.js.map +1 -0
- package/cjs/guards/positive_infinity.d.ts +19 -0
- package/cjs/guards/positive_infinity.d.ts.map +1 -0
- package/cjs/guards/positive_infinity.js +25 -0
- package/cjs/guards/positive_infinity.js.map +1 -0
- package/cjs/guards/positive_zero.d.ts +17 -0
- package/cjs/guards/positive_zero.d.ts.map +1 -0
- package/cjs/guards/positive_zero.js +36 -0
- package/cjs/guards/positive_zero.js.map +1 -0
- package/cjs/guards/safe_integer.d.ts +33 -0
- package/cjs/guards/safe_integer.d.ts.map +1 -0
- package/cjs/guards/safe_integer.js +27 -0
- package/cjs/guards/safe_integer.js.map +1 -0
- package/cjs/hypot.d.ts +18 -0
- package/cjs/hypot.d.ts.map +1 -0
- package/cjs/hypot.js +63 -0
- package/cjs/hypot.js.map +1 -0
- package/cjs/ieee754.d.ts +16 -0
- package/cjs/ieee754.d.ts.map +1 -0
- package/cjs/ieee754.js +32 -0
- package/cjs/ieee754.js.map +1 -0
- package/cjs/imul.d.ts +17 -0
- package/cjs/imul.d.ts.map +1 -0
- package/cjs/imul.js +24 -0
- package/cjs/imul.js.map +1 -0
- package/cjs/index.d.ts +84 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +113 -0
- package/cjs/index.js.map +1 -0
- package/cjs/internal/ieee754.d.ts +174 -0
- package/cjs/internal/ieee754.d.ts.map +1 -0
- package/cjs/internal/ieee754.js +200 -0
- package/cjs/internal/ieee754.js.map +1 -0
- package/cjs/internal/primordials.d.ts +30 -0
- package/cjs/internal/primordials.d.ts.map +1 -0
- package/cjs/internal/primordials.js +30 -0
- package/cjs/internal/primordials.js.map +1 -0
- package/cjs/log.d.ts +9 -0
- package/cjs/log.d.ts.map +1 -0
- package/cjs/log.js +46 -0
- package/cjs/log.js.map +1 -0
- package/cjs/log10.d.ts +9 -0
- package/cjs/log10.d.ts.map +1 -0
- package/cjs/log10.js +21 -0
- package/cjs/log10.js.map +1 -0
- package/cjs/log1p.d.ts +10 -0
- package/cjs/log1p.d.ts.map +1 -0
- package/cjs/log1p.js +32 -0
- package/cjs/log1p.js.map +1 -0
- package/cjs/log2.d.ts +12 -0
- package/cjs/log2.d.ts.map +1 -0
- package/cjs/log2.js +24 -0
- package/cjs/log2.js.map +1 -0
- package/cjs/max.d.ts +22 -0
- package/cjs/max.d.ts.map +1 -0
- package/cjs/max.js +51 -0
- package/cjs/max.js.map +1 -0
- package/cjs/min.d.ts +10 -0
- package/cjs/min.d.ts.map +1 -0
- package/cjs/min.js +36 -0
- package/cjs/min.js.map +1 -0
- package/cjs/package.json +3 -0
- package/cjs/pow.d.ts +31 -0
- package/cjs/pow.d.ts.map +1 -0
- package/cjs/pow.js +36 -0
- package/cjs/pow.js.map +1 -0
- package/cjs/random.d.ts +93 -0
- package/cjs/random.d.ts.map +1 -0
- package/cjs/random.js +242 -0
- package/cjs/random.js.map +1 -0
- package/cjs/round.d.ts +9 -0
- package/cjs/round.d.ts.map +1 -0
- package/cjs/round.js +24 -0
- package/cjs/round.js.map +1 -0
- package/cjs/sign.d.ts +17 -0
- package/cjs/sign.d.ts.map +1 -0
- package/cjs/sign.js +22 -0
- package/cjs/sign.js.map +1 -0
- package/cjs/sin.d.ts +14 -0
- package/cjs/sin.d.ts.map +1 -0
- package/cjs/sin.js +31 -0
- package/cjs/sin.js.map +1 -0
- package/cjs/sinh.d.ts +14 -0
- package/cjs/sinh.d.ts.map +1 -0
- package/cjs/sinh.js +22 -0
- package/cjs/sinh.js.map +1 -0
- package/cjs/sqrt.d.ts +19 -0
- package/cjs/sqrt.d.ts.map +1 -0
- package/cjs/sqrt.js +45 -0
- package/cjs/sqrt.js.map +1 -0
- package/cjs/tan.d.ts +9 -0
- package/cjs/tan.d.ts.map +1 -0
- package/cjs/tan.js +26 -0
- package/cjs/tan.js.map +1 -0
- package/cjs/tanh.d.ts +17 -0
- package/cjs/tanh.d.ts.map +1 -0
- package/cjs/tanh.js +34 -0
- package/cjs/tanh.js.map +1 -0
- package/cjs/trunc.d.ts +21 -0
- package/cjs/trunc.d.ts.map +1 -0
- package/cjs/trunc.js +50 -0
- package/cjs/trunc.js.map +1 -0
- package/cjs/types/finite.d.ts +16 -0
- package/cjs/types/finite.d.ts.map +1 -0
- package/cjs/types/finite.js +4 -0
- package/cjs/types/finite.js.map +1 -0
- package/cjs/types/float.d.ts +65 -0
- package/cjs/types/float.d.ts.map +1 -0
- package/cjs/types/float.js +4 -0
- package/cjs/types/float.js.map +1 -0
- package/cjs/types/index.d.ts +6 -0
- package/cjs/types/index.d.ts.map +1 -0
- package/cjs/types/index.js +22 -0
- package/cjs/types/index.js.map +1 -0
- package/cjs/types/integer.d.ts +147 -0
- package/cjs/types/integer.d.ts.map +1 -0
- package/cjs/types/integer.js +5 -0
- package/cjs/types/integer.js.map +1 -0
- package/cjs/types/precision.d.ts +46 -0
- package/cjs/types/precision.d.ts.map +1 -0
- package/cjs/types/precision.js +9 -0
- package/cjs/types/precision.js.map +1 -0
- package/cjs/types/safe_integer.d.ts +17 -0
- package/cjs/types/safe_integer.d.ts.map +1 -0
- package/cjs/types/safe_integer.js +5 -0
- package/cjs/types/safe_integer.js.map +1 -0
- package/esm/abs.d.ts +14 -0
- package/esm/abs.d.ts.map +1 -0
- package/esm/abs.js +19 -0
- package/esm/abs.js.map +1 -0
- package/esm/acos.d.ts +17 -0
- package/esm/acos.d.ts.map +1 -0
- package/esm/acos.js +24 -0
- package/esm/acos.js.map +1 -0
- package/esm/acosh.d.ts +11 -0
- package/esm/acosh.d.ts.map +1 -0
- package/esm/acosh.js +32 -0
- package/esm/acosh.js.map +1 -0
- package/esm/asin.d.ts +11 -0
- package/esm/asin.d.ts.map +1 -0
- package/esm/asin.js +25 -0
- package/esm/asin.js.map +1 -0
- package/esm/asinh.d.ts +9 -0
- package/esm/asinh.d.ts.map +1 -0
- package/esm/asinh.js +23 -0
- package/esm/asinh.js.map +1 -0
- package/esm/atan.d.ts +11 -0
- package/esm/atan.d.ts.map +1 -0
- package/esm/atan.js +62 -0
- package/esm/atan.js.map +1 -0
- package/esm/atan2.d.ts +12 -0
- package/esm/atan2.d.ts.map +1 -0
- package/esm/atan2.js +67 -0
- package/esm/atan2.js.map +1 -0
- package/esm/atanh.d.ts +11 -0
- package/esm/atanh.d.ts.map +1 -0
- package/esm/atanh.js +29 -0
- package/esm/atanh.js.map +1 -0
- package/esm/cbrt.d.ts +9 -0
- package/esm/cbrt.d.ts.map +1 -0
- package/esm/cbrt.js +23 -0
- package/esm/cbrt.js.map +1 -0
- package/esm/ceil.d.ts +15 -0
- package/esm/ceil.d.ts.map +1 -0
- package/esm/ceil.js +31 -0
- package/esm/ceil.js.map +1 -0
- package/esm/clamp.d.ts +15 -0
- package/esm/clamp.d.ts.map +1 -0
- package/esm/clamp.js +29 -0
- package/esm/clamp.js.map +1 -0
- package/esm/clz32.d.ts +20 -0
- package/esm/clz32.d.ts.map +1 -0
- package/esm/clz32.js +45 -0
- package/esm/clz32.js.map +1 -0
- package/esm/constants/e.d.ts +17 -0
- package/esm/constants/e.d.ts.map +1 -0
- package/esm/constants/e.js +16 -0
- package/esm/constants/e.js.map +1 -0
- package/esm/constants/epsilon.d.ts +24 -0
- package/esm/constants/epsilon.d.ts.map +1 -0
- package/esm/constants/epsilon.js +23 -0
- package/esm/constants/epsilon.js.map +1 -0
- package/esm/constants/index.d.ts +23 -0
- package/esm/constants/index.d.ts.map +1 -0
- package/esm/constants/index.js +23 -0
- package/esm/constants/index.js.map +1 -0
- package/esm/constants/infinity.d.ts +3 -0
- package/esm/constants/infinity.d.ts.map +1 -0
- package/esm/constants/infinity.js +3 -0
- package/esm/constants/infinity.js.map +1 -0
- package/esm/constants/ln10.d.ts +10 -0
- package/esm/constants/ln10.d.ts.map +1 -0
- package/esm/constants/ln10.js +9 -0
- package/esm/constants/ln10.js.map +1 -0
- package/esm/constants/ln2.d.ts +10 -0
- package/esm/constants/ln2.d.ts.map +1 -0
- package/esm/constants/ln2.js +9 -0
- package/esm/constants/ln2.js.map +1 -0
- package/esm/constants/log10e.d.ts +10 -0
- package/esm/constants/log10e.d.ts.map +1 -0
- package/esm/constants/log10e.js +9 -0
- package/esm/constants/log10e.js.map +1 -0
- package/esm/constants/log2e.d.ts +10 -0
- package/esm/constants/log2e.d.ts.map +1 -0
- package/esm/constants/log2e.js +9 -0
- package/esm/constants/log2e.js.map +1 -0
- package/esm/constants/max_safe_integer.d.ts +11 -0
- package/esm/constants/max_safe_integer.d.ts.map +1 -0
- package/esm/constants/max_safe_integer.js +10 -0
- package/esm/constants/max_safe_integer.js.map +1 -0
- package/esm/constants/max_value.d.ts +10 -0
- package/esm/constants/max_value.d.ts.map +1 -0
- package/esm/constants/max_value.js +9 -0
- package/esm/constants/max_value.js.map +1 -0
- package/esm/constants/min_safe_integer.d.ts +12 -0
- package/esm/constants/min_safe_integer.d.ts.map +1 -0
- package/esm/constants/min_safe_integer.js +11 -0
- package/esm/constants/min_safe_integer.js.map +1 -0
- package/esm/constants/min_value.d.ts +10 -0
- package/esm/constants/min_value.d.ts.map +1 -0
- package/esm/constants/min_value.js +9 -0
- package/esm/constants/min_value.js.map +1 -0
- package/esm/constants/nan.d.ts +47 -0
- package/esm/constants/nan.d.ts.map +1 -0
- package/esm/constants/nan.js +27 -0
- package/esm/constants/nan.js.map +1 -0
- package/esm/constants/negative_infinity.d.ts +28 -0
- package/esm/constants/negative_infinity.d.ts.map +1 -0
- package/esm/constants/negative_infinity.js +12 -0
- package/esm/constants/negative_infinity.js.map +1 -0
- package/esm/constants/negative_zero.d.ts +31 -0
- package/esm/constants/negative_zero.d.ts.map +1 -0
- package/esm/constants/negative_zero.js +18 -0
- package/esm/constants/negative_zero.js.map +1 -0
- package/esm/constants/pi.d.ts +10 -0
- package/esm/constants/pi.d.ts.map +1 -0
- package/esm/constants/pi.js +9 -0
- package/esm/constants/pi.js.map +1 -0
- package/esm/constants/positive_infinity.d.ts +29 -0
- package/esm/constants/positive_infinity.d.ts.map +1 -0
- package/esm/constants/positive_infinity.js +13 -0
- package/esm/constants/positive_infinity.js.map +1 -0
- package/esm/constants/positive_zero.d.ts +38 -0
- package/esm/constants/positive_zero.d.ts.map +1 -0
- package/esm/constants/positive_zero.js +33 -0
- package/esm/constants/positive_zero.js.map +1 -0
- package/esm/constants/sqrt1_2.d.ts +9 -0
- package/esm/constants/sqrt1_2.d.ts.map +1 -0
- package/esm/constants/sqrt1_2.js +8 -0
- package/esm/constants/sqrt1_2.js.map +1 -0
- package/esm/constants/sqrt2.d.ts +9 -0
- package/esm/constants/sqrt2.d.ts.map +1 -0
- package/esm/constants/sqrt2.js +8 -0
- package/esm/constants/sqrt2.js.map +1 -0
- package/esm/cos.d.ts +10 -0
- package/esm/cos.d.ts.map +1 -0
- package/esm/cos.js +29 -0
- package/esm/cos.js.map +1 -0
- package/esm/cosh.d.ts +10 -0
- package/esm/cosh.d.ts.map +1 -0
- package/esm/cosh.js +18 -0
- package/esm/cosh.js.map +1 -0
- package/esm/exp.d.ts +20 -0
- package/esm/exp.d.ts.map +1 -0
- package/esm/exp.js +45 -0
- package/esm/exp.js.map +1 -0
- package/esm/expm1.d.ts +11 -0
- package/esm/expm1.d.ts.map +1 -0
- package/esm/expm1.js +35 -0
- package/esm/expm1.js.map +1 -0
- package/esm/f16round.d.ts +24 -0
- package/esm/f16round.d.ts.map +1 -0
- package/esm/f16round.js +39 -0
- package/esm/f16round.js.map +1 -0
- package/esm/float16/constants.d.ts +97 -0
- package/esm/float16/constants.d.ts.map +1 -0
- package/esm/float16/constants.js +96 -0
- package/esm/float16/constants.js.map +1 -0
- package/esm/float16/decode.d.ts +40 -0
- package/esm/float16/decode.d.ts.map +1 -0
- package/esm/float16/decode.js +61 -0
- package/esm/float16/decode.js.map +1 -0
- package/esm/float16/encode.d.ts +67 -0
- package/esm/float16/encode.d.ts.map +1 -0
- package/esm/float16/encode.js +71 -0
- package/esm/float16/encode.js.map +1 -0
- package/esm/float16/guards.d.ts +22 -0
- package/esm/float16/guards.d.ts.map +1 -0
- package/esm/float16/guards.js +12 -0
- package/esm/float16/guards.js.map +1 -0
- package/esm/float16/index.d.ts +11 -0
- package/esm/float16/index.d.ts.map +1 -0
- package/esm/float16/index.js +11 -0
- package/esm/float16/index.js.map +1 -0
- package/esm/float16/round.d.ts +25 -0
- package/esm/float16/round.d.ts.map +1 -0
- package/esm/float16/round.js +43 -0
- package/esm/float16/round.js.map +1 -0
- package/esm/float32/constants.d.ts +96 -0
- package/esm/float32/constants.d.ts.map +1 -0
- package/esm/float32/constants.js +95 -0
- package/esm/float32/constants.js.map +1 -0
- package/esm/float32/decode.d.ts +38 -0
- package/esm/float32/decode.d.ts.map +1 -0
- package/esm/float32/decode.js +64 -0
- package/esm/float32/decode.js.map +1 -0
- package/esm/float32/encode.d.ts +50 -0
- package/esm/float32/encode.d.ts.map +1 -0
- package/esm/float32/encode.js +71 -0
- package/esm/float32/encode.js.map +1 -0
- package/esm/float32/guards.d.ts +37 -0
- package/esm/float32/guards.d.ts.map +1 -0
- package/esm/float32/guards.js +16 -0
- package/esm/float32/guards.js.map +1 -0
- package/esm/float32/index.d.ts +11 -0
- package/esm/float32/index.d.ts.map +1 -0
- package/esm/float32/index.js +11 -0
- package/esm/float32/index.js.map +1 -0
- package/esm/float32/round.d.ts +23 -0
- package/esm/float32/round.d.ts.map +1 -0
- package/esm/float32/round.js +33 -0
- package/esm/float32/round.js.map +1 -0
- package/esm/floor.d.ts +10 -0
- package/esm/floor.d.ts.map +1 -0
- package/esm/floor.js +29 -0
- package/esm/floor.js.map +1 -0
- package/esm/fround.d.ts +23 -0
- package/esm/fround.d.ts.map +1 -0
- package/esm/fround.js +32 -0
- package/esm/fround.js.map +1 -0
- package/esm/guards/finite.d.ts +23 -0
- package/esm/guards/finite.d.ts.map +1 -0
- package/esm/guards/finite.js +18 -0
- package/esm/guards/finite.js.map +1 -0
- package/esm/guards/index.d.ts +50 -0
- package/esm/guards/index.d.ts.map +1 -0
- package/esm/guards/index.js +50 -0
- package/esm/guards/index.js.map +1 -0
- package/esm/guards/infinity.d.ts +3 -0
- package/esm/guards/infinity.d.ts.map +1 -0
- package/esm/guards/infinity.js +3 -0
- package/esm/guards/infinity.js.map +1 -0
- package/esm/guards/integer.d.ts +47 -0
- package/esm/guards/integer.d.ts.map +1 -0
- package/esm/guards/integer.js +19 -0
- package/esm/guards/integer.js.map +1 -0
- package/esm/guards/nan.d.ts +61 -0
- package/esm/guards/nan.d.ts.map +1 -0
- package/esm/guards/nan.js +63 -0
- package/esm/guards/nan.js.map +1 -0
- package/esm/guards/negative_infinity.d.ts +19 -0
- package/esm/guards/negative_infinity.d.ts.map +1 -0
- package/esm/guards/negative_infinity.js +21 -0
- package/esm/guards/negative_infinity.js.map +1 -0
- package/esm/guards/negative_zero.d.ts +12 -0
- package/esm/guards/negative_zero.d.ts.map +1 -0
- package/esm/guards/negative_zero.js +20 -0
- package/esm/guards/negative_zero.js.map +1 -0
- package/esm/guards/positive_infinity.d.ts +19 -0
- package/esm/guards/positive_infinity.d.ts.map +1 -0
- package/esm/guards/positive_infinity.js +21 -0
- package/esm/guards/positive_infinity.js.map +1 -0
- package/esm/guards/positive_zero.d.ts +17 -0
- package/esm/guards/positive_zero.d.ts.map +1 -0
- package/esm/guards/positive_zero.js +19 -0
- package/esm/guards/positive_zero.js.map +1 -0
- package/esm/guards/safe_integer.d.ts +33 -0
- package/esm/guards/safe_integer.d.ts.map +1 -0
- package/esm/guards/safe_integer.js +22 -0
- package/esm/guards/safe_integer.js.map +1 -0
- package/esm/hypot.d.ts +18 -0
- package/esm/hypot.d.ts.map +1 -0
- package/esm/hypot.js +60 -0
- package/esm/hypot.js.map +1 -0
- package/esm/ieee754.d.ts +16 -0
- package/esm/ieee754.d.ts.map +1 -0
- package/esm/ieee754.js +16 -0
- package/esm/ieee754.js.map +1 -0
- package/esm/imul.d.ts +17 -0
- package/esm/imul.d.ts.map +1 -0
- package/esm/imul.js +21 -0
- package/esm/imul.js.map +1 -0
- package/esm/index.d.ts +84 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +84 -0
- package/esm/index.js.map +1 -0
- package/esm/internal/ieee754.d.ts +174 -0
- package/esm/internal/ieee754.d.ts.map +1 -0
- package/esm/internal/ieee754.js +194 -0
- package/esm/internal/ieee754.js.map +1 -0
- package/esm/internal/primordials.d.ts +30 -0
- package/esm/internal/primordials.d.ts.map +1 -0
- package/esm/internal/primordials.js +27 -0
- package/esm/internal/primordials.js.map +1 -0
- package/esm/log.d.ts +9 -0
- package/esm/log.d.ts.map +1 -0
- package/esm/log.js +43 -0
- package/esm/log.js.map +1 -0
- package/esm/log10.d.ts +9 -0
- package/esm/log10.d.ts.map +1 -0
- package/esm/log10.js +18 -0
- package/esm/log10.js.map +1 -0
- package/esm/log1p.d.ts +10 -0
- package/esm/log1p.d.ts.map +1 -0
- package/esm/log1p.js +29 -0
- package/esm/log1p.js.map +1 -0
- package/esm/log2.d.ts +12 -0
- package/esm/log2.d.ts.map +1 -0
- package/esm/log2.js +21 -0
- package/esm/log2.js.map +1 -0
- package/esm/max.d.ts +22 -0
- package/esm/max.d.ts.map +1 -0
- package/esm/max.js +48 -0
- package/esm/max.js.map +1 -0
- package/esm/min.d.ts +10 -0
- package/esm/min.d.ts.map +1 -0
- package/esm/min.js +33 -0
- package/esm/min.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/pow.d.ts +31 -0
- package/esm/pow.d.ts.map +1 -0
- package/esm/pow.js +33 -0
- package/esm/pow.js.map +1 -0
- package/esm/random.d.ts +93 -0
- package/esm/random.d.ts.map +1 -0
- package/esm/random.js +237 -0
- package/esm/random.js.map +1 -0
- package/esm/round.d.ts +9 -0
- package/esm/round.d.ts.map +1 -0
- package/esm/round.js +21 -0
- package/esm/round.js.map +1 -0
- package/esm/sign.d.ts +17 -0
- package/esm/sign.d.ts.map +1 -0
- package/esm/sign.js +19 -0
- package/esm/sign.js.map +1 -0
- package/esm/sin.d.ts +14 -0
- package/esm/sin.d.ts.map +1 -0
- package/esm/sin.js +28 -0
- package/esm/sin.js.map +1 -0
- package/esm/sinh.d.ts +14 -0
- package/esm/sinh.d.ts.map +1 -0
- package/esm/sinh.js +19 -0
- package/esm/sinh.js.map +1 -0
- package/esm/sqrt.d.ts +19 -0
- package/esm/sqrt.d.ts.map +1 -0
- package/esm/sqrt.js +42 -0
- package/esm/sqrt.js.map +1 -0
- package/esm/tan.d.ts +9 -0
- package/esm/tan.d.ts.map +1 -0
- package/esm/tan.js +23 -0
- package/esm/tan.js.map +1 -0
- package/esm/tanh.d.ts +17 -0
- package/esm/tanh.d.ts.map +1 -0
- package/esm/tanh.js +31 -0
- package/esm/tanh.js.map +1 -0
- package/esm/trunc.d.ts +21 -0
- package/esm/trunc.d.ts.map +1 -0
- package/esm/trunc.js +47 -0
- package/esm/trunc.js.map +1 -0
- package/esm/types/finite.d.ts +16 -0
- package/esm/types/finite.d.ts.map +1 -0
- package/esm/types/finite.js +3 -0
- package/esm/types/finite.js.map +1 -0
- package/esm/types/float.d.ts +65 -0
- package/esm/types/float.d.ts.map +1 -0
- package/esm/types/float.js +3 -0
- package/esm/types/float.js.map +1 -0
- package/esm/types/index.d.ts +6 -0
- package/esm/types/index.d.ts.map +1 -0
- package/esm/types/index.js +6 -0
- package/esm/types/index.js.map +1 -0
- package/esm/types/integer.d.ts +147 -0
- package/esm/types/integer.d.ts.map +1 -0
- package/esm/types/integer.js +4 -0
- package/esm/types/integer.js.map +1 -0
- package/esm/types/precision.d.ts +46 -0
- package/esm/types/precision.d.ts.map +1 -0
- package/esm/types/precision.js +8 -0
- package/esm/types/precision.js.map +1 -0
- package/esm/types/safe_integer.d.ts +17 -0
- package/esm/types/safe_integer.d.ts.map +1 -0
- package/esm/types/safe_integer.js +4 -0
- package/esm/types/safe_integer.js.map +1 -0
- package/package.json +1834 -0
- package/src/abs.ts +18 -0
- package/src/acos.ts +24 -0
- package/src/acosh.ts +28 -0
- package/src/asin.ts +24 -0
- package/src/asinh.ts +21 -0
- package/src/atan.ts +64 -0
- package/src/atan2.ts +58 -0
- package/src/atanh.ts +26 -0
- package/src/cbrt.ts +22 -0
- package/src/ceil.ts +27 -0
- package/src/clamp.ts +29 -0
- package/src/clz32.ts +45 -0
- package/src/constants/e.ts +18 -0
- package/src/constants/epsilon.ts +25 -0
- package/src/constants/index.ts +22 -0
- package/src/constants/infinity.ts +2 -0
- package/src/constants/ln10.ts +9 -0
- package/src/constants/ln2.ts +9 -0
- package/src/constants/log10e.ts +9 -0
- package/src/constants/log2e.ts +9 -0
- package/src/constants/max_safe_integer.ts +10 -0
- package/src/constants/max_value.ts +9 -0
- package/src/constants/min_safe_integer.ts +11 -0
- package/src/constants/min_value.ts +9 -0
- package/src/constants/nan.ts +57 -0
- package/src/constants/negative_infinity.ts +28 -0
- package/src/constants/negative_zero.ts +34 -0
- package/src/constants/pi.ts +9 -0
- package/src/constants/positive_infinity.ts +30 -0
- package/src/constants/positive_zero.ts +41 -0
- package/src/constants/sqrt1_2.ts +8 -0
- package/src/constants/sqrt2.ts +8 -0
- package/src/cos.ts +29 -0
- package/src/cosh.ts +18 -0
- package/src/exp.ts +45 -0
- package/src/expm1.ts +31 -0
- package/src/f16round.ts +39 -0
- package/src/float16/constants.ts +106 -0
- package/src/float16/decode.ts +61 -0
- package/src/float16/encode.ts +72 -0
- package/src/float16/guards.ts +33 -0
- package/src/float16/index.ts +10 -0
- package/src/float16/round.ts +43 -0
- package/src/float32/constants.ts +105 -0
- package/src/float32/decode.ts +64 -0
- package/src/float32/encode.ts +71 -0
- package/src/float32/guards.ts +54 -0
- package/src/float32/index.ts +10 -0
- package/src/float32/round.ts +33 -0
- package/src/floor.ts +26 -0
- package/src/fround.ts +32 -0
- package/src/guards/finite.ts +45 -0
- package/src/guards/index.ts +49 -0
- package/src/guards/infinity.ts +2 -0
- package/src/guards/integer.ts +62 -0
- package/src/guards/nan.ts +65 -0
- package/src/guards/negative_infinity.ts +22 -0
- package/src/guards/negative_zero.ts +21 -0
- package/src/guards/positive_infinity.ts +22 -0
- package/src/guards/positive_zero.ts +19 -0
- package/src/guards/safe_integer.ts +56 -0
- package/src/hypot.ts +59 -0
- package/src/ieee754.ts +15 -0
- package/src/imul.ts +21 -0
- package/src/index.ts +84 -0
- package/src/internal/ieee754.ts +255 -0
- package/src/internal/primordials.ts +33 -0
- package/src/log.ts +42 -0
- package/src/log10.ts +18 -0
- package/src/log1p.ts +26 -0
- package/src/log2.ts +21 -0
- package/src/max.ts +46 -0
- package/src/min.ts +32 -0
- package/src/pow.ts +33 -0
- package/src/random.ts +241 -0
- package/src/round.ts +20 -0
- package/src/sign.ts +19 -0
- package/src/sin.ts +29 -0
- package/src/sinh.ts +19 -0
- package/src/sqrt.ts +40 -0
- package/src/tan.ts +22 -0
- package/src/tanh.ts +28 -0
- package/src/trunc.ts +44 -0
- package/src/types/finite.ts +23 -0
- package/src/types/float.ts +74 -0
- package/src/types/index.ts +5 -0
- package/src/types/integer.ts +167 -0
- package/src/types/precision.ts +51 -0
- package/src/types/safe_integer.ts +18 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Float16 } from "../types/float.js";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is a valid {@linkcode Float16} as per IEEE 754-2008.
|
|
4
|
+
*
|
|
5
|
+
* @param it The value to check.
|
|
6
|
+
* @returns `true` if the value is a float16 number, `false` otherwise.
|
|
7
|
+
* @see https://en.wikipedia.org/wiki/Half-precision_floating-point_format
|
|
8
|
+
* @see https://en.wikipedia.org/wiki/IEEE_754
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { isFloat16 } from "@nick/math/float16/guards";
|
|
12
|
+
*
|
|
13
|
+
* console.log(isFloat16(0.5)); // true
|
|
14
|
+
* console.log(isFloat16(0.1)); // false
|
|
15
|
+
* ```
|
|
16
|
+
* @see {@linkcode isFloat32} for a similar function for float32 numbers.
|
|
17
|
+
* @category Guards
|
|
18
|
+
* @tags float16
|
|
19
|
+
*/
|
|
20
|
+
export declare function isFloat16<N extends number>(it: N): it is Float16<N>;
|
|
21
|
+
export declare function isFloat16(it: unknown): it is Float16<number>;
|
|
22
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/float16/guards.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;AACrE,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This submodule provides type guards specific to the float16 module of the
|
|
3
|
+
* `@nick/math` library, namely the {@linkcode isFloat16} predicate function.
|
|
4
|
+
*
|
|
5
|
+
* @module float16/guards
|
|
6
|
+
*/
|
|
7
|
+
import { isNaN } from "../guards/nan.js";
|
|
8
|
+
import { roundFloat16 } from "./round.js";
|
|
9
|
+
export function isFloat16(it) {
|
|
10
|
+
return typeof it === "number" && !isNaN(it) && it === roundFloat16(it);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/float16/guards.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAsB1C,MAAM,UAAU,SAAS,CAAC,EAAW;IACnC,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for working with `float16` values (16-bit half precision floating
|
|
3
|
+
* point numbers), as defined by IEEE 754-2008.
|
|
4
|
+
*
|
|
5
|
+
* @module float16
|
|
6
|
+
*/
|
|
7
|
+
export * from "./decode.js";
|
|
8
|
+
export * from "./encode.js";
|
|
9
|
+
export * from "./guards.js";
|
|
10
|
+
export * from "./round.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/float16/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for working with `float16` values (16-bit half precision floating
|
|
3
|
+
* point numbers), as defined by IEEE 754-2008.
|
|
4
|
+
*
|
|
5
|
+
* @module float16
|
|
6
|
+
*/
|
|
7
|
+
export * from "./decode.js";
|
|
8
|
+
export * from "./encode.js";
|
|
9
|
+
export * from "./guards.js";
|
|
10
|
+
export * from "./round.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/float16/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rounds a number to the nearest 16-bit floating point value (half precision).
|
|
3
|
+
*
|
|
4
|
+
* Based on `Math.f16round` function from the TC39 Proposal for [Float16Array],
|
|
5
|
+
* which began shipping in ES2024, this function follows the same rounding and
|
|
6
|
+
* conversion rules as per the IEEE 754-2008 specification for half-precision
|
|
7
|
+
* floating-point numbers (also known as binary16).
|
|
8
|
+
*
|
|
9
|
+
* [Float16Array]: https://github.com/tc39/proposal-float16array
|
|
10
|
+
*
|
|
11
|
+
* @param x The number to round.
|
|
12
|
+
* @returns The 16-bit floating point rounded value of the number.
|
|
13
|
+
* @category Rounding
|
|
14
|
+
* @tags float, float16
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { roundFloat16 } from "@nick/math/float16/round";
|
|
18
|
+
* import { PI } from "@nick/math/constants";
|
|
19
|
+
* import assert from "node:assert";
|
|
20
|
+
*
|
|
21
|
+
* assert.strictEqual(roundFloat16(PI), 3.140625); // OK
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function roundFloat16(x: number): number;
|
|
25
|
+
//# sourceMappingURL=round.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round.d.ts","sourceRoot":"","sources":["../../src/float16/round.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides functions for rounding numbers to 16-bit floating point
|
|
3
|
+
* values that follow the IEEE 754-2008 standard for half-precision binary16
|
|
4
|
+
* floating point numbers.
|
|
5
|
+
*
|
|
6
|
+
* The `roundFloat16` function rounds a number to the nearest 16-bit floating
|
|
7
|
+
* point value (half precision), following the same rounding and conversion
|
|
8
|
+
* rules as the native `Math.f16round` function from the TC39 Proposal for
|
|
9
|
+
* [Float16Array], which began shipping in ES2024.
|
|
10
|
+
*
|
|
11
|
+
* [Float16Array]: https://github.com/tc39/proposal-float16array
|
|
12
|
+
*
|
|
13
|
+
* @module float16/round
|
|
14
|
+
*/
|
|
15
|
+
import { encodeFloat16 } from "./encode.js";
|
|
16
|
+
import { decodeFloat16 } from "./decode.js";
|
|
17
|
+
/**
|
|
18
|
+
* Rounds a number to the nearest 16-bit floating point value (half precision).
|
|
19
|
+
*
|
|
20
|
+
* Based on `Math.f16round` function from the TC39 Proposal for [Float16Array],
|
|
21
|
+
* which began shipping in ES2024, this function follows the same rounding and
|
|
22
|
+
* conversion rules as per the IEEE 754-2008 specification for half-precision
|
|
23
|
+
* floating-point numbers (also known as binary16).
|
|
24
|
+
*
|
|
25
|
+
* [Float16Array]: https://github.com/tc39/proposal-float16array
|
|
26
|
+
*
|
|
27
|
+
* @param x The number to round.
|
|
28
|
+
* @returns The 16-bit floating point rounded value of the number.
|
|
29
|
+
* @category Rounding
|
|
30
|
+
* @tags float, float16
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { roundFloat16 } from "@nick/math/float16/round";
|
|
34
|
+
* import { PI } from "@nick/math/constants";
|
|
35
|
+
* import assert from "node:assert";
|
|
36
|
+
*
|
|
37
|
+
* assert.strictEqual(roundFloat16(PI), 3.140625); // OK
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function roundFloat16(x) {
|
|
41
|
+
return decodeFloat16(encodeFloat16(+x));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=round.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round.js","sourceRoot":"","sources":["../../src/float16/round.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,YAAY,CAAC,CAAS;IACpC,OAAO,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides constants used by the encoding/decoding APIs in the
|
|
3
|
+
* `@nick/math/float32` suite. These are primarily used to handle special cases
|
|
4
|
+
* such as `NaN`, `Infinity`, and `-0`, which have unique representations in
|
|
5
|
+
* the IEEE-754 half-precision floating point format.
|
|
6
|
+
*
|
|
7
|
+
* These are intended for primarily internal use, but are exported for the sake
|
|
8
|
+
* of completeness and transparency, as well as for potential userland usage in
|
|
9
|
+
* cases where the constants are needed for custom encoding/decoding logic.
|
|
10
|
+
*
|
|
11
|
+
* @module float32/constants
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The number of bits used for the exponent in the IEEE-754 single-precision
|
|
15
|
+
* (or "binary32") format.
|
|
16
|
+
*
|
|
17
|
+
* @category Constants
|
|
18
|
+
* @tags float32, ieee-754, exponent
|
|
19
|
+
*/
|
|
20
|
+
export declare const FLOAT32_EXPONENT_BITS = 8;
|
|
21
|
+
/**
|
|
22
|
+
* The number of bits used for the mantissa in the IEEE-754 single-precision
|
|
23
|
+
* (or "binary32") format.
|
|
24
|
+
*
|
|
25
|
+
* @category Constants
|
|
26
|
+
* @tags float32, ieee-754, mantissa
|
|
27
|
+
*/
|
|
28
|
+
export declare const FLOAT32_MANTISSA_BITS = 23;
|
|
29
|
+
/**
|
|
30
|
+
* The exponent bias used in the IEEE-754 single-precision (or "binary32") format.
|
|
31
|
+
*
|
|
32
|
+
* @category Constants
|
|
33
|
+
* @tags float32, ieee-754, exponent, bias
|
|
34
|
+
*/
|
|
35
|
+
export declare const FLOAT32_EXPONENT_BIAS = 127;
|
|
36
|
+
/**
|
|
37
|
+
* Well-known bit pattern representing `NaN` in the IEEE-754 single-precision (or
|
|
38
|
+
* "binary32") format.
|
|
39
|
+
*
|
|
40
|
+
* @category Constants
|
|
41
|
+
* @tags float32, ieee-754, NaN
|
|
42
|
+
*/
|
|
43
|
+
export declare const FLOAT32_NAN = 2143289344;
|
|
44
|
+
/**
|
|
45
|
+
* Well-known bit pattern representing `+Infinity` (positive infinity) in the
|
|
46
|
+
* IEEE-754 single-precision (or "binary32") format.
|
|
47
|
+
*
|
|
48
|
+
* @category Constants
|
|
49
|
+
* @tags float32, ieee-754, Infinity
|
|
50
|
+
*/
|
|
51
|
+
export declare const FLOAT32_POSITIVE_INFINITY = 2139095040;
|
|
52
|
+
/**
|
|
53
|
+
* Well-known bit pattern representing `-Infinity` (negative infinity) in the
|
|
54
|
+
* IEEE-754 single-precision (or "binary32") format.
|
|
55
|
+
*
|
|
56
|
+
* @category Constants
|
|
57
|
+
* @tags float32, ieee-754, Infinity
|
|
58
|
+
*/
|
|
59
|
+
export declare const FLOAT32_NEGATIVE_INFINITY = 4286578688;
|
|
60
|
+
/**
|
|
61
|
+
* Well-known bit pattern representing `-0` (negative zero) in the IEEE-754
|
|
62
|
+
* single-precision (or "binary32") format.
|
|
63
|
+
*
|
|
64
|
+
* @category Constants
|
|
65
|
+
* @tags float32, ieee-754, zero
|
|
66
|
+
*/
|
|
67
|
+
export declare const FLOAT32_NEGATIVE_ZERO = 2147483648;
|
|
68
|
+
/**
|
|
69
|
+
* Well-known bit pattern representing `+0` (positive zero) in the IEEE-754
|
|
70
|
+
* single-precision (or "binary32") format.
|
|
71
|
+
*
|
|
72
|
+
* **Note**: This constant, unlike the others, is equivalent to its bit pattern
|
|
73
|
+
* representation (all bits are zero). As such, this is not strictly necessary
|
|
74
|
+
* for encoding/decoding, but is included for completeness and consistency.
|
|
75
|
+
*
|
|
76
|
+
* @category Constants
|
|
77
|
+
* @tags float32, ieee-754, zero
|
|
78
|
+
*/
|
|
79
|
+
export declare const FLOAT32_POSITIVE_ZERO = 0;
|
|
80
|
+
/**
|
|
81
|
+
* Represents the IEEE-754 binary32 (single-precision) floating-point format.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
declare const _default: {
|
|
86
|
+
readonly exponent: 8;
|
|
87
|
+
readonly mantissa: 23;
|
|
88
|
+
readonly bias: 127;
|
|
89
|
+
readonly nan: 2143289344;
|
|
90
|
+
readonly positive_infinity: 2139095040;
|
|
91
|
+
readonly negative_infinity: 4286578688;
|
|
92
|
+
readonly negative_zero: 2147483648;
|
|
93
|
+
readonly positive_zero: 0;
|
|
94
|
+
};
|
|
95
|
+
export default _default;
|
|
96
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/float32/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,aAAa,CAAC;AAEtC;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,aAAa,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,aAAa,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,aAAa,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,IAAa,CAAC;AAEhD;;;;GAIG;;;;;;;;;;;AACH,wBASiC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides constants used by the encoding/decoding APIs in the
|
|
3
|
+
* `@nick/math/float32` suite. These are primarily used to handle special cases
|
|
4
|
+
* such as `NaN`, `Infinity`, and `-0`, which have unique representations in
|
|
5
|
+
* the IEEE-754 half-precision floating point format.
|
|
6
|
+
*
|
|
7
|
+
* These are intended for primarily internal use, but are exported for the sake
|
|
8
|
+
* of completeness and transparency, as well as for potential userland usage in
|
|
9
|
+
* cases where the constants are needed for custom encoding/decoding logic.
|
|
10
|
+
*
|
|
11
|
+
* @module float32/constants
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The number of bits used for the exponent in the IEEE-754 single-precision
|
|
15
|
+
* (or "binary32") format.
|
|
16
|
+
*
|
|
17
|
+
* @category Constants
|
|
18
|
+
* @tags float32, ieee-754, exponent
|
|
19
|
+
*/
|
|
20
|
+
export const FLOAT32_EXPONENT_BITS = 8;
|
|
21
|
+
/**
|
|
22
|
+
* The number of bits used for the mantissa in the IEEE-754 single-precision
|
|
23
|
+
* (or "binary32") format.
|
|
24
|
+
*
|
|
25
|
+
* @category Constants
|
|
26
|
+
* @tags float32, ieee-754, mantissa
|
|
27
|
+
*/
|
|
28
|
+
export const FLOAT32_MANTISSA_BITS = 23;
|
|
29
|
+
/**
|
|
30
|
+
* The exponent bias used in the IEEE-754 single-precision (or "binary32") format.
|
|
31
|
+
*
|
|
32
|
+
* @category Constants
|
|
33
|
+
* @tags float32, ieee-754, exponent, bias
|
|
34
|
+
*/
|
|
35
|
+
export const FLOAT32_EXPONENT_BIAS = 127;
|
|
36
|
+
/**
|
|
37
|
+
* Well-known bit pattern representing `NaN` in the IEEE-754 single-precision (or
|
|
38
|
+
* "binary32") format.
|
|
39
|
+
*
|
|
40
|
+
* @category Constants
|
|
41
|
+
* @tags float32, ieee-754, NaN
|
|
42
|
+
*/
|
|
43
|
+
export const FLOAT32_NAN = 0x7FC00000;
|
|
44
|
+
/**
|
|
45
|
+
* Well-known bit pattern representing `+Infinity` (positive infinity) in the
|
|
46
|
+
* IEEE-754 single-precision (or "binary32") format.
|
|
47
|
+
*
|
|
48
|
+
* @category Constants
|
|
49
|
+
* @tags float32, ieee-754, Infinity
|
|
50
|
+
*/
|
|
51
|
+
export const FLOAT32_POSITIVE_INFINITY = 0x7F800000;
|
|
52
|
+
/**
|
|
53
|
+
* Well-known bit pattern representing `-Infinity` (negative infinity) in the
|
|
54
|
+
* IEEE-754 single-precision (or "binary32") format.
|
|
55
|
+
*
|
|
56
|
+
* @category Constants
|
|
57
|
+
* @tags float32, ieee-754, Infinity
|
|
58
|
+
*/
|
|
59
|
+
export const FLOAT32_NEGATIVE_INFINITY = 0xFF800000;
|
|
60
|
+
/**
|
|
61
|
+
* Well-known bit pattern representing `-0` (negative zero) in the IEEE-754
|
|
62
|
+
* single-precision (or "binary32") format.
|
|
63
|
+
*
|
|
64
|
+
* @category Constants
|
|
65
|
+
* @tags float32, ieee-754, zero
|
|
66
|
+
*/
|
|
67
|
+
export const FLOAT32_NEGATIVE_ZERO = 0x80000000;
|
|
68
|
+
/**
|
|
69
|
+
* Well-known bit pattern representing `+0` (positive zero) in the IEEE-754
|
|
70
|
+
* single-precision (or "binary32") format.
|
|
71
|
+
*
|
|
72
|
+
* **Note**: This constant, unlike the others, is equivalent to its bit pattern
|
|
73
|
+
* representation (all bits are zero). As such, this is not strictly necessary
|
|
74
|
+
* for encoding/decoding, but is included for completeness and consistency.
|
|
75
|
+
*
|
|
76
|
+
* @category Constants
|
|
77
|
+
* @tags float32, ieee-754, zero
|
|
78
|
+
*/
|
|
79
|
+
export const FLOAT32_POSITIVE_ZERO = 0x00000000;
|
|
80
|
+
/**
|
|
81
|
+
* Represents the IEEE-754 binary32 (single-precision) floating-point format.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
export default {
|
|
86
|
+
exponent: FLOAT32_EXPONENT_BITS,
|
|
87
|
+
mantissa: FLOAT32_MANTISSA_BITS,
|
|
88
|
+
bias: FLOAT32_EXPONENT_BIAS,
|
|
89
|
+
nan: FLOAT32_NAN,
|
|
90
|
+
positive_infinity: FLOAT32_POSITIVE_INFINITY,
|
|
91
|
+
negative_infinity: FLOAT32_NEGATIVE_INFINITY,
|
|
92
|
+
negative_zero: FLOAT32_NEGATIVE_ZERO,
|
|
93
|
+
positive_zero: FLOAT32_POSITIVE_ZERO,
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/float32/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,UAAU,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,UAAU,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC;AAEhD;;;;GAIG;AACH,eAAe;IACb,QAAQ,EAAE,qBAAqB;IAC/B,QAAQ,EAAE,qBAAqB;IAC/B,IAAI,EAAE,qBAAqB;IAC3B,GAAG,EAAE,WAAW;IAChB,iBAAiB,EAAE,yBAAyB;IAC5C,iBAAiB,EAAE,yBAAyB;IAC5C,aAAa,EAAE,qBAAqB;IACpC,aAAa,EAAE,qBAAqB;CACN,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a 32-bit unsigned integer (`Uint32`) into a 32-bit single-precision
|
|
3
|
+
* floating point value (`Float32`) with 23 bits of mantissa. This function
|
|
4
|
+
* follows the IEEE 754-2008 spec for single-precision floating point numbers.
|
|
5
|
+
*
|
|
6
|
+
* The input value is expected to be the result of an encoding operation, such
|
|
7
|
+
* as the value returned by the {@linkcode encodeFloat32} function, or by
|
|
8
|
+
* DataView's `getUint32` method when reading a single-precision float.
|
|
9
|
+
*
|
|
10
|
+
* This function is used internally by the {@linkcode fround} function to
|
|
11
|
+
* convert the intermediate value back into a standard JavaScript number.
|
|
12
|
+
*
|
|
13
|
+
* ## Special Cases
|
|
14
|
+
*
|
|
15
|
+
* The following special cases are handled separately, short-circuiting the
|
|
16
|
+
* decoding process to return a well-known constant value (as per IEEE spec):
|
|
17
|
+
*
|
|
18
|
+
* - `0x7FC00000` (2139095040) decodes to `NaN`
|
|
19
|
+
* - `0x7F800000` (2139095040) decodes to `+Infinity`
|
|
20
|
+
* - `0xFF800000` (4286578688) decodes to `-Infinity`
|
|
21
|
+
* - `0x80000000` (2147483648) decodes to `-0`
|
|
22
|
+
*
|
|
23
|
+
* @param bits The encoded 32-bit single-precision floating point value.
|
|
24
|
+
* @returns The decoded standard JavaScript number.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { decodeFloat32 } from "@nick/math/float32";
|
|
28
|
+
*
|
|
29
|
+
* console.log(decodeFloat32(0x40490FDB)); // 3.
|
|
30
|
+
*
|
|
31
|
+
* const view = new DataView(new Float32Array([3.14]).buffer);
|
|
32
|
+
* console.log(decodeFloat32(view.getUint32(0)));
|
|
33
|
+
* ```
|
|
34
|
+
* @category IEEE-754
|
|
35
|
+
* @tags float, float32, decode
|
|
36
|
+
*/
|
|
37
|
+
export declare function decodeFloat32(bits: number): number;
|
|
38
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/float32/decode.ts"],"names":[],"mappings":"AAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides functions for decoding 32-bit single-precision floating
|
|
3
|
+
* point numbers (`Float32`) from IEEE 754-2008 encoded `Uint32` values, like
|
|
4
|
+
* those returned by {@linkcode encodeFloat32} or DataView's `geUint32` method.
|
|
5
|
+
*
|
|
6
|
+
* The `Float32` format is a 32-bit representation of a floating point number
|
|
7
|
+
* that follows the IEEE 754-2008 standard for single-precision binary32
|
|
8
|
+
* floating point numbers. This format is used to store floating point values
|
|
9
|
+
* in a DataView via `setUint32`, and is equivalent to the result of calling
|
|
10
|
+
* `DataView.prototype.getUint32` when reading a single-precision float.
|
|
11
|
+
*
|
|
12
|
+
* To encode a standard JavaScript number into a `Float32` value, use the
|
|
13
|
+
* {@linkcode encodeFloat32} function of the `./encode` module, passing it the
|
|
14
|
+
* number you want to encode. The result can then be stored in a DataView via
|
|
15
|
+
* `setUint32`, or used as an intermediate value for further processing.
|
|
16
|
+
*
|
|
17
|
+
* To decode the `Float32` value back into a standard JavaScript number (but
|
|
18
|
+
* with 32-bits of precision), use the {@linkcode decodeFloat32} function of
|
|
19
|
+
* this module, passing it the encoded value.
|
|
20
|
+
*
|
|
21
|
+
* @module float32/decode
|
|
22
|
+
*/
|
|
23
|
+
import float32 from "./constants.js";
|
|
24
|
+
import { decode } from "../internal/ieee754.js";
|
|
25
|
+
/**
|
|
26
|
+
* Decodes a 32-bit unsigned integer (`Uint32`) into a 32-bit single-precision
|
|
27
|
+
* floating point value (`Float32`) with 23 bits of mantissa. This function
|
|
28
|
+
* follows the IEEE 754-2008 spec for single-precision floating point numbers.
|
|
29
|
+
*
|
|
30
|
+
* The input value is expected to be the result of an encoding operation, such
|
|
31
|
+
* as the value returned by the {@linkcode encodeFloat32} function, or by
|
|
32
|
+
* DataView's `getUint32` method when reading a single-precision float.
|
|
33
|
+
*
|
|
34
|
+
* This function is used internally by the {@linkcode fround} function to
|
|
35
|
+
* convert the intermediate value back into a standard JavaScript number.
|
|
36
|
+
*
|
|
37
|
+
* ## Special Cases
|
|
38
|
+
*
|
|
39
|
+
* The following special cases are handled separately, short-circuiting the
|
|
40
|
+
* decoding process to return a well-known constant value (as per IEEE spec):
|
|
41
|
+
*
|
|
42
|
+
* - `0x7FC00000` (2139095040) decodes to `NaN`
|
|
43
|
+
* - `0x7F800000` (2139095040) decodes to `+Infinity`
|
|
44
|
+
* - `0xFF800000` (4286578688) decodes to `-Infinity`
|
|
45
|
+
* - `0x80000000` (2147483648) decodes to `-0`
|
|
46
|
+
*
|
|
47
|
+
* @param bits The encoded 32-bit single-precision floating point value.
|
|
48
|
+
* @returns The decoded standard JavaScript number.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { decodeFloat32 } from "@nick/math/float32";
|
|
52
|
+
*
|
|
53
|
+
* console.log(decodeFloat32(0x40490FDB)); // 3.
|
|
54
|
+
*
|
|
55
|
+
* const view = new DataView(new Float32Array([3.14]).buffer);
|
|
56
|
+
* console.log(decodeFloat32(view.getUint32(0)));
|
|
57
|
+
* ```
|
|
58
|
+
* @category IEEE-754
|
|
59
|
+
* @tags float, float32, decode
|
|
60
|
+
*/
|
|
61
|
+
export function decodeFloat32(bits) {
|
|
62
|
+
return decode(bits, float32);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/float32/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a standard JavaScript number (a 64-bit double-precision floating
|
|
3
|
+
* point value, 52 bits of mantissa) into a 32-bit unsigned integer (Uint32).
|
|
4
|
+
* This function follows the IEEE 754-2008 standard for single-precision 32-bit
|
|
5
|
+
* floating point numbers, also known as `Float32` (or `binary32`).
|
|
6
|
+
*
|
|
7
|
+
* This function is used internally by the {@linkcode fround} function to
|
|
8
|
+
* convert the input number into a portable intermediate form, which it then
|
|
9
|
+
* transforms into the `Float32` format via the {@linkcode decodeFloat32}.
|
|
10
|
+
*
|
|
11
|
+
* The returned value can be used to store single-precision floating point
|
|
12
|
+
* values in a DataView via `setUint32`, since it is equivalent to the result
|
|
13
|
+
* of `DataView.prototype.getUint32` when reading a single-precision float.
|
|
14
|
+
*
|
|
15
|
+
* ## Encoding Scheme
|
|
16
|
+
*
|
|
17
|
+
* The encoding scheme varies based on the input value classification:
|
|
18
|
+
*
|
|
19
|
+
* - Normal (within the normal range of representable values)
|
|
20
|
+
* - Subnormal (too small to be represented with full precision)
|
|
21
|
+
* - Special cases (see below)
|
|
22
|
+
*
|
|
23
|
+
* ## Special Cases
|
|
24
|
+
*
|
|
25
|
+
* The following special cases are handled separately, short-circuiting the
|
|
26
|
+
* encoding process to return a well-known constant value:
|
|
27
|
+
*
|
|
28
|
+
* - `NaN` is encoded as `0x7FC00000` (2139095040).
|
|
29
|
+
* - `Infinity` is encoded as `0x7F800000` (2139095040).
|
|
30
|
+
* - `-Infinity` is encoded as `0xFF800000` (4286578688).
|
|
31
|
+
* - `-0` is encoded as `0x80000000` (2147483648).
|
|
32
|
+
*
|
|
33
|
+
* @param value The standard JavaScript number to encode.
|
|
34
|
+
* @returns An encoded unsigned 32-bit integer that represents the input value.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { encodeFloat32 } from "@nick/math/ieee754";
|
|
38
|
+
*
|
|
39
|
+
* console.log(encodeFloat32(3.14)); // 0x40490FDB (1078523339)
|
|
40
|
+
*
|
|
41
|
+
* const view = new DataView(new ArrayBuffer(4));
|
|
42
|
+
* view.setUint32(0, encodeFloat32(3.14));
|
|
43
|
+
* console.log(view.getUint32(0)); // 1078523339
|
|
44
|
+
* console.log(view.getFloat32(0)); // 3.140625
|
|
45
|
+
* ```
|
|
46
|
+
* @category IEEE-754
|
|
47
|
+
* @tags float32, encode
|
|
48
|
+
*/
|
|
49
|
+
export declare function encodeFloat32(value: number): number;
|
|
50
|
+
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/float32/encode.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides functions for encoding standard JavaScript numbers
|
|
3
|
+
* (64-bit double-precision floating point values) into 32-bit unsigned
|
|
4
|
+
* integers (Uint32) that represent single-precision floating point numbers.
|
|
5
|
+
*
|
|
6
|
+
* The `Float32` format is a 32-bit representation of a floating point number
|
|
7
|
+
* that follows the IEEE 754-2008 standard for single-precision binary32
|
|
8
|
+
* floating point numbers. This format is used to store floating point values
|
|
9
|
+
* in a DataView via `setUint32`, and is equivalent to the result of calling
|
|
10
|
+
* `DataView.prototype.getUint32` when reading a single-precision float.
|
|
11
|
+
*
|
|
12
|
+
* To decode a `Float32` value back into a standard JavaScript number, use the
|
|
13
|
+
* {@linkcode decodeFloat32} function of the `./decode` module, passing it the
|
|
14
|
+
* encoded value returned by {@linkcode encodeFloat32}.
|
|
15
|
+
*
|
|
16
|
+
* @module float32/encode
|
|
17
|
+
*/
|
|
18
|
+
import float32 from "./constants.js";
|
|
19
|
+
import { encode } from "../internal/ieee754.js";
|
|
20
|
+
/**
|
|
21
|
+
* Encodes a standard JavaScript number (a 64-bit double-precision floating
|
|
22
|
+
* point value, 52 bits of mantissa) into a 32-bit unsigned integer (Uint32).
|
|
23
|
+
* This function follows the IEEE 754-2008 standard for single-precision 32-bit
|
|
24
|
+
* floating point numbers, also known as `Float32` (or `binary32`).
|
|
25
|
+
*
|
|
26
|
+
* This function is used internally by the {@linkcode fround} function to
|
|
27
|
+
* convert the input number into a portable intermediate form, which it then
|
|
28
|
+
* transforms into the `Float32` format via the {@linkcode decodeFloat32}.
|
|
29
|
+
*
|
|
30
|
+
* The returned value can be used to store single-precision floating point
|
|
31
|
+
* values in a DataView via `setUint32`, since it is equivalent to the result
|
|
32
|
+
* of `DataView.prototype.getUint32` when reading a single-precision float.
|
|
33
|
+
*
|
|
34
|
+
* ## Encoding Scheme
|
|
35
|
+
*
|
|
36
|
+
* The encoding scheme varies based on the input value classification:
|
|
37
|
+
*
|
|
38
|
+
* - Normal (within the normal range of representable values)
|
|
39
|
+
* - Subnormal (too small to be represented with full precision)
|
|
40
|
+
* - Special cases (see below)
|
|
41
|
+
*
|
|
42
|
+
* ## Special Cases
|
|
43
|
+
*
|
|
44
|
+
* The following special cases are handled separately, short-circuiting the
|
|
45
|
+
* encoding process to return a well-known constant value:
|
|
46
|
+
*
|
|
47
|
+
* - `NaN` is encoded as `0x7FC00000` (2139095040).
|
|
48
|
+
* - `Infinity` is encoded as `0x7F800000` (2139095040).
|
|
49
|
+
* - `-Infinity` is encoded as `0xFF800000` (4286578688).
|
|
50
|
+
* - `-0` is encoded as `0x80000000` (2147483648).
|
|
51
|
+
*
|
|
52
|
+
* @param value The standard JavaScript number to encode.
|
|
53
|
+
* @returns An encoded unsigned 32-bit integer that represents the input value.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { encodeFloat32 } from "@nick/math/ieee754";
|
|
57
|
+
*
|
|
58
|
+
* console.log(encodeFloat32(3.14)); // 0x40490FDB (1078523339)
|
|
59
|
+
*
|
|
60
|
+
* const view = new DataView(new ArrayBuffer(4));
|
|
61
|
+
* view.setUint32(0, encodeFloat32(3.14));
|
|
62
|
+
* console.log(view.getUint32(0)); // 1078523339
|
|
63
|
+
* console.log(view.getFloat32(0)); // 3.140625
|
|
64
|
+
* ```
|
|
65
|
+
* @category IEEE-754
|
|
66
|
+
* @tags float32, encode
|
|
67
|
+
*/
|
|
68
|
+
export function encodeFloat32(value) {
|
|
69
|
+
return encode(value, float32);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/float32/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Finite } from "../guards/finite.js";
|
|
2
|
+
import type { Float32 } from "../types/float.js";
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a value is a valid {@linkcode Float32} as per IEEE 754-2008.
|
|
5
|
+
*
|
|
6
|
+
* @param it The value to check.
|
|
7
|
+
* @returns `true` if the value is a {@linkcode Float32}; otherwise, false.
|
|
8
|
+
* @see https://en.wikipedia.org/wiki/Single-precision_floating-point_format
|
|
9
|
+
* @see https://en.wikipedia.org/wiki/IEEE_754
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { isFloat32 } from "@nick/math/float32/guards";
|
|
13
|
+
*
|
|
14
|
+
* console.log(isFloat32(0.5)); // true
|
|
15
|
+
* console.log(isFloat32(0.1)); // false
|
|
16
|
+
* ```
|
|
17
|
+
* @see {@linkcode isFloat16} for a similar function for float16 numbers.
|
|
18
|
+
* @category Guards
|
|
19
|
+
* @tags float32
|
|
20
|
+
*/
|
|
21
|
+
export declare function isFloat32<N extends number>(it: N): it is Float32<N>;
|
|
22
|
+
export declare function isFloat32(it: unknown): it is Float32<number>;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the given value is a finite float32 number, as per the IEEE
|
|
25
|
+
* 754-2008 spec. This is a stricter version of {@linkcode isFloat32} that also
|
|
26
|
+
* checks if the value is finite, i.e. neither `Infinity`, `-Infinity`, nor
|
|
27
|
+
* `NaN`.
|
|
28
|
+
*
|
|
29
|
+
* @param value The value to check.
|
|
30
|
+
* @returns `true` if the value is a finite float32 number, `false` otherwise.
|
|
31
|
+
* @see {@linkcode isFloat32} for a less strict version of this function.
|
|
32
|
+
* @category Guards
|
|
33
|
+
* @tags float32
|
|
34
|
+
*/
|
|
35
|
+
export declare function isFiniteFloat32<N extends number>(it: N): it is Finite<N> & Float32<N>;
|
|
36
|
+
export declare function isFiniteFloat32(it: unknown): it is Float32<number>;
|
|
37
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/float32/guards.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,MAAM,EAAY,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;AACrE,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;AAK9D;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC9C,EAAE,EAAE,CAAC,GACJ,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAChC,wBAAgB,eAAe,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This submodule provides type guards specific to the float32 module of the
|
|
3
|
+
* `@nick/math` library, namely the {@linkcode isFloat32} predicate function.
|
|
4
|
+
*
|
|
5
|
+
* @module float32/guards
|
|
6
|
+
*/
|
|
7
|
+
import { isNaN } from "../guards/nan.js";
|
|
8
|
+
import { isFinite } from "../guards/finite.js";
|
|
9
|
+
import { roundFloat32 } from "./round.js";
|
|
10
|
+
export function isFloat32(it) {
|
|
11
|
+
return typeof it === "number" && !isNaN(it) && it === roundFloat32(it);
|
|
12
|
+
}
|
|
13
|
+
export function isFiniteFloat32(it) {
|
|
14
|
+
return isFloat32(it) && isFinite(it);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/float32/guards.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAe,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAsB1C,MAAM,UAAU,SAAS,CAAC,EAAW;IACnC,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC,CAAC;AACzE,CAAC;AAkBD,MAAM,UAAU,eAAe,CAAC,EAAW;IACzC,OAAO,SAAS,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC;AACvC,CAAC"}
|