effect-io-ai

Package: effect
Module: BigDecimal

BigDecimal.divideUnsafe

Provides an unsafe division operation on BigDecimals.

When to use

Use when you need to divide BigDecimal values where the divisor is known to be non-zero, so division by zero should be a thrown exception.

Details

If the dividend is not a multiple of the divisor, the result will be a BigDecimal value with up to the default division precision.

Gotchas

Throws a RangeError if the divisor is 0.

Example (Dividing decimals unsafely)

import { BigDecimal } from "effect"

console.log(BigDecimal.divideUnsafe(BigDecimal.fromStringUnsafe("6"), BigDecimal.fromStringUnsafe("3"))) // BigDecimal(2)
console.log(BigDecimal.divideUnsafe(BigDecimal.fromStringUnsafe("6"), BigDecimal.fromStringUnsafe("4"))) // BigDecimal(1.5)

See

Signature

declare const divideUnsafe: { (that: BigDecimal): (self: BigDecimal) => BigDecimal; (self: BigDecimal, that: BigDecimal): BigDecimal; }

Source

Since v4.0.0