@basic-math/divide
v0.1.0
Published
Type-safe division operation with SafeNumber validation and zero-division protection
Maintainers
Readme
@basic-math/divide
Type-safe division operation with SafeNumber validation and division-by-zero protection.
Installation
npm install @basic-math/divide @basic-math/coreUsage
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');
}Features
- Type-safe division using SafeNumber
- Runtime validation
- Division-by-zero protection
- Handles positive, negative, and decimal numbers
- Zero dependencies (except @basic-math/core)
API
divide(a: number, b: number): number
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
License
MIT
