MCPcopy Index your code
hub / github.com/Effect-TS/effect / normalize

Function normalize

packages/effect/src/BigDecimal.ts:146–173  ·  view source on GitHub ↗
(self: BigDecimal)

Source from the content-addressed store, hash-verified

144 * @category scaling
145 */
146export const normalize = (self: BigDecimal): BigDecimal => {
147 if (self.normalized === undefined) {
148 if (self.value === bigint0) {
149 self.normalized = zero
150 } else {
151 const digits = `${self.value}`
152
153 let trail = 0
154 for (let i = digits.length - 1; i >= 0; i--) {
155 if (digits[i] === "0") {
156 trail++
157 } else {
158 break
159 }
160 }
161
162 if (trail === 0) {
163 self.normalized = self
164 }
165
166 const value = BigInt(digits.substring(0, digits.length - trail))
167 const scale = self.scale - trail
168 self.normalized = unsafeMakeNormalized(value, scale)
169 }
170 }
171
172 return self.normalized
173}
174
175/**
176 * Scales a given `BigDecimal` to the specified scale.

Callers 4

[Hash.symbol]Function · 0.70
formatFunction · 0.70
toExponentialFunction · 0.70
isIntegerFunction · 0.70

Calls 1

unsafeMakeNormalizedFunction · 0.85

Tested by

no test coverage detected