MCPcopy
hub / github.com/formatjs/formatjs / mod

Method mod

packages/bigdecimal/index.ts:311–355  ·  view source on GitHub ↗
(y: BigDecimal | number | string | bigint)

Source from the content-addressed store, hash-verified

309 }
310
311 mod(y: BigDecimal | number | string | bigint): BigDecimal {
312 const other = BigDecimal._coerce(y)
313 if (this._special || other._special) {
314 if (
315 this._special === SpecialValue.NAN ||
316 other._special === SpecialValue.NAN
317 ) {
318 return BigDecimal._create(0n, 0, SpecialValue.NAN, false)
319 }
320 if (
321 this._special === SpecialValue.POSITIVE_INFINITY ||
322 this._special === SpecialValue.NEGATIVE_INFINITY
323 ) {
324 return BigDecimal._create(0n, 0, SpecialValue.NAN, false)
325 }
326 if (
327 other._special === SpecialValue.POSITIVE_INFINITY ||
328 other._special === SpecialValue.NEGATIVE_INFINITY
329 ) {
330 return this
331 }
332 }
333 if (other._mantissa === 0n) {
334 return BigDecimal._create(0n, 0, SpecialValue.NAN, false)
335 }
336 if (this._mantissa === 0n) {
337 return this
338 }
339
340 // Align exponents
341 let m1 = this._mantissa
342 let m2 = other._mantissa
343 const e1 = this._exponent
344 const e2 = other._exponent
345 const minE = Math.min(e1, e2)
346 if (e1 > minE) m1 *= bigintPow10(e1 - minE)
347 if (e2 > minE) m2 *= bigintPow10(e2 - minE)
348
349 const remainder = m1 % m2
350 if (remainder === 0n) {
351 return BigDecimal._create(0n, 0, SpecialValue.NONE, false)
352 }
353 const [nm, ne] = removeTrailingZeros(remainder, minE)
354 return BigDecimal._create(nm, ne, SpecialValue.NONE, false)
355 }
356
357 abs(): BigDecimal {
358 if (this._special === SpecialValue.NAN) return this

Callers 2

bigdecimal.test.tsFile · 0.80

Calls 4

bigintPow10Function · 0.85
removeTrailingZerosFunction · 0.85
_coerceMethod · 0.80
_createMethod · 0.80

Tested by

no test coverage detected