Type-safe division operation with SafeNumber validation and zero-division protection
npm install @basic-math/divideType-safe division operation with SafeNumber validation and division-by-zero protection.
``bash`
npm install @basic-math/divide @basic-math/core
`typescript
import { divide } from '@basic-math/divide';
const result = divide(20, 4); // 5
const decimal = divide(10, 3); // 3.333...
const negative = divide(-15, 3); // -5
// Division by zero throws an error
try {
divide(10, 0); // Throws error
} catch (error) {
console.error('Cannot divide by zero');
}
`
- Type-safe division using SafeNumber
- Runtime validation
- Division-by-zero protection
- Handles positive, negative, and decimal numbers
- Zero dependencies (except @basic-math/core)
Divides the first number by the second with validation.
Parameters:
- a - Dividend (number to be divided)b` - Divisor (number to divide by)
-
Returns: Quotient of a divided by b
Throws:
- TypeViolationError or NumericInvariantError if inputs are invalid
- Error if divisor is zero
MIT