MCPcopy
hub / github.com/formatjs/formatjs / constructor

Method constructor

packages/bigdecimal/index.ts:159–207  ·  view source on GitHub ↗
(value: number | string | bigint)

Source from the content-addressed store, hash-verified

157 readonly _negativeZero: boolean
158
159 constructor(value: number | string | bigint) {
160 if (typeof value === 'bigint') {
161 const [m, e] = removeTrailingZeros(value, 0)
162 this._mantissa = m
163 this._exponent = e
164 this._special = SpecialValue.NONE
165 this._negativeZero = false
166 return
167 }
168
169 if (typeof value === 'number') {
170 if (Number.isNaN(value)) {
171 this._mantissa = 0n
172 this._exponent = 0
173 this._special = SpecialValue.NAN
174 this._negativeZero = false
175 return
176 }
177 if (value === Infinity) {
178 this._mantissa = 0n
179 this._exponent = 0
180 this._special = SpecialValue.POSITIVE_INFINITY
181 this._negativeZero = false
182 return
183 }
184 if (value === -Infinity) {
185 this._mantissa = 0n
186 this._exponent = 0
187 this._special = SpecialValue.NEGATIVE_INFINITY
188 this._negativeZero = false
189 return
190 }
191 if (value === 0) {
192 this._mantissa = 0n
193 this._exponent = 0
194 this._special = SpecialValue.NONE
195 this._negativeZero = Object.is(value, -0)
196 return
197 }
198 // Convert via string to preserve exact decimal representation
199 value = String(value)
200 }
201
202 const parsed = parseDecimalString(value)
203 this._mantissa = parsed.mantissa
204 this._exponent = parsed.exponent
205 this._special = parsed.special
206 this._negativeZero = parsed.negativeZero
207 }
208
209 // Private constructor for internal use
210 private static _create(

Callers

nothing calls this directly

Calls 3

removeTrailingZerosFunction · 0.85
parseDecimalStringFunction · 0.85
isNaNMethod · 0.80

Tested by

no test coverage detected