MCPcopy Create free account
hub / github.com/Effect-TS/effect / decimalScale

Function decimalScale

packages/effect/src/encoding/SchemaBinary.ts:1162–1172  ·  view source on GitHub ↗
(value: number)

Source from the content-addressed store, hash-verified

1160
1161// The scale that makes `value` an exact short-decimal mantissa, or 0.
1162function decimalScale(value: number): number {
1163 for (let scale = 1; scale <= DECIMAL_SCALE_MAX; scale++) {
1164 const mantissa = Math.round(value * POW10[scale])
1165 // The mantissa only grows with the scale, so once it leaves the range no
1166 // later scale can fit; this also rejects NaN and the infinities in one
1167 // comparison.
1168 if (!(mantissa >= -DECIMAL_MANTISSA_MAX && mantissa <= DECIMAL_MANTISSA_MAX)) return 0
1169 if (mantissa / POW10[scale] === value) return scale
1170 }
1171 return 0
1172}
1173
1174// Sign-magnitude preserves `-0`, unlike zigzag.
1175function decodeSignMagnitude(code: number): number {

Callers 3

valueWireCodeFunction · 0.85
encodeNumberRunFunction · 0.85
encodeValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected