zen-unique-name-my-math
v1.1.0
Published
A basic arithmetic operations
Readme
zen-unique-name-my-math
A simple math utility library for Node.js that provides basic arithmetic operations.
Installation
npm install zen-unique-name-my-mathAPI
add(a, b)
Parameters:
a(number): The first number to addb(number): The second number to add
Returns: (number) The sum of a and b
Throws: TypeError if either argument is not a number
Description: Adds two numbers together and returns the result. Supports both integers and floating-point numbers.
Examples:
const add = require('zen-unique-name-my-math');
// Adding integers
add(5, 3); // Returns 8
add(10, -5); // Returns 5
// Adding decimals
add(2.5, 1.5); // Returns 4
add(0.1, 0.2); // Returns 0.30000000000000004 (note: floating point precision)
// Adding negative numbers
add(-5, -3); // Returns -8
add(-5, 3); // Returns -2Error Handling:
try {
add('5', 3); // Throws TypeError: Both arguments must be numbers
} catch (err) {
console.error(err.message);
}mult(a, b)
Parameters:
a(number): The first number to multiplyb(number): The second number to multiply
Returns: (number) The product of a and b
Throws: TypeError if either argument is not a number
Description: Multiplies two numbers together and returns the result. Supports both integers and floating-point numbers.
Examples:
const { add, mult } = require('zen-unique-name-my-math');
// Multiplying integers
mult(5, 3); // Returns 15
mult(10, -2); // Returns -20
// Multiplying decimals
mult(2.5, 4); // Returns 10
mult(0.5, 0.5); // Returns 0.25
// Multiplying negative numbers
mult(-5, -3); // Returns 15
mult(-5, 3); // Returns -15Error Handling:
try {
mult('5', 3); // Throws TypeError: Both arguments must be numbers
} catch (err) {
console.error(err.message);
}