MCPcopy
hub / github.com/formatjs/formatjs / div

Method div

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

Source from the content-addressed store, hash-verified

246 }
247
248 div(y: BigDecimal | number | string | bigint): BigDecimal {
249 const other = BigDecimal._coerce(y)
250 if (this._special || other._special) {
251 return this._specialArith(other, 'div')
252 }
253 if (other._mantissa === 0n) {
254 if (this._mantissa === 0n) {
255 return BigDecimal._create(0n, 0, SpecialValue.NAN, false)
256 }
257 const neg = this._isSignNegative() !== other._isSignNegative()
258 return BigDecimal._create(
259 0n,
260 0,
261 neg ? SpecialValue.NEGATIVE_INFINITY : SpecialValue.POSITIVE_INFINITY,
262 false
263 )
264 }
265 if (this._mantissa === 0n) {
266 const negZero = this._isSignNegative() !== other._isSignNegative()
267 return BigDecimal._create(0n, 0, SpecialValue.NONE, negZero)
268 }
269 // Scale numerator for precision
270 const scaledNumerator = this._mantissa * bigintPow10(DIV_PRECISION)
271 const quotient = scaledNumerator / other._mantissa
272 const newExponent = this._exponent - other._exponent - DIV_PRECISION
273 const [nm, ne] = removeTrailingZeros(quotient, newExponent)
274 return BigDecimal._create(nm, ne, SpecialValue.NONE, false)
275 }
276
277 plus(y: BigDecimal | number | string | bigint): BigDecimal {
278 const other = BigDecimal._coerce(y)

Callers 10

powMethod · 0.80
logMethod · 0.80
bigdecimal.test.tsFile · 0.80
findN1E1R1Function · 0.80
findN2E2R2Function · 0.80
findN1R1Function · 0.80
findN2R2Function · 0.80

Calls 6

_specialArithMethod · 0.95
_isSignNegativeMethod · 0.95
bigintPow10Function · 0.85
removeTrailingZerosFunction · 0.85
_coerceMethod · 0.80
_createMethod · 0.80

Tested by

no test coverage detected