adv_calculator
v1.1.11
Published
Scientific Calculator
Downloads
29
Maintainers
Readme
Arithmetic Functions Module
A Node.js module providing basic arithmetic functions: addition, subtraction, multiplication, and division. This module is designed for educational purposes to demonstrate how to write and test JavaScript functions.
Table of Contents
Overview
This module includes the following functions:
Arithmetic Functions
add(a, b)
: Returns the sum ofa
andb
.subtract(a, b)
: Returns the difference whenb
is subtracted froma
.multiply(a, b)
: Returns the product ofa
andb
.divide(a, b)
: Returns the quotient whena
is divided byb
. Throws an error ifb
is zero.exponential(base, exponent)
: Returns the result ofbase
raised to the power ofexponent
.modulus(a, b)
: Returns the remainder whena
is divided byb
.squareRoot(a)
: Returns the square root ofa
.absolute(a)
: Returns the absolute value ofa
.factorial(n)
: Returns the factorial ofn
.gcd(a, b)
: Returns the greatest common divisor ofa
andb
.lcm(a, b)
: Returns the lowest common multiple ofa
andb
.
Bitwise Functions
bitwiseAnd(a, b)
: Performs a bitwise AND operation ona
andb
.bitwiseOr(a, b)
: Performs a bitwise OR operation ona
andb
.bitwiseXor(a, b)
: Performs a bitwise XOR operation ona
andb
.bitwiseNot(a)
: Performs a bitwise NOT operation ona
.leftShift(a, b)
: Performs a left bitwise shift ona
byb
bits.rightShift(a, b)
: Performs a right bitwise shift ona
byb
bits.zeroFillRightShift(a, b)
: Performs a zero-fill right shift ona
byb
bits.
Additional Functions
cubeRoot(a)
: Returns the cube root ofa
.logarithm(a)
: Returns the natural logarithm ofa
.sine(angle)
: Returns the sine of the angle (in radians).cosine(angle)
: Returns the cosine of the angle (in radians).tangent(angle)
: Returns the tangent of the angle (in radians).sinh(x)
: Returns the hyperbolic sine ofx
.cosh(x)
: Returns the hyperbolic cosine ofx
.tanh(x)
: Returns the hyperbolic tangent ofx
.asin(x)
: Returns the arcsine ofx
.acos(x)
: Returns the arccosine ofx
.atan(x)
: Returns the arctangent ofx
.
Installation
To use this module in your project, follow these steps:
Clone the repository:
git clone https://github.com/TyRoopam9599/adv_calculator.git
Navigate to the project directory:
cd adv_calculator
Install dependencies:
This project uses Mocha for testing. Install it along with other dependencies using:
npm install
Usage
You can use the functions by requiring the module in your Node.js application. Here’s how you can do it:
const {
add,
subtract,
multiply,
divide,
exponential,
modulus,
bitwiseAnd,
bitwiseOr,
bitwiseXor,
bitwiseNot,
leftShift,
rightShift,
zeroFillRightShift,
squareRoot,
absolute,
factorial,
gcd,
lcm,
cubeRoot,
logarithm,
sine,
cosine,
tangent,
sinh,
cosh,
tanh,
asin,
acos,
atan
} = require('./index');
console.log(add(2, 3)); // Output: 5
console.log(subtract(5, 2)); // Output: 3
console.log(multiply(2, 3)); // Output: 6
console.log(divide(6, 2)); // Output: 3
console.log(modulus(5, 2)); // Output: 1
console.log(exponential(2, 3)); // Output: 8
console.log(squareRoot(9)); // Output: 3
console.log(absolute(-5)); // Output: 5
console.log(factorial(5)); // Output: 120
console.log(gcd(5,2)) ; // Output: 1
condole.log(lcm(5,2)) ; // Output: 10
console.log(bitwiseAnd(5, 3)); // Output: 1
console.log(bitwiseOr(5, 3)); // Output: 7
console.log(bitwiseXor(5, 3)); // Output: 6
console.log(bitwiseNot(5)); // Output: -6
console.log(leftShift(5, 1)); // Output: 10
console.log(rightShift(5, 1)); // Output: 2
console.log(zeroFillRightShift(5, 1)); // Output: 2
console.log(cubeRoot(27)); // Output: 3
console.log(logarithm(Math.E)); // Output: 1
console.log(sine(0)); // Output: 0
console.log(cosine(0)); // Output: 1
console.log(tangent(0)); // Output: 0
console.log(sinh(0)); // Output: 0
console.log(cosh(0)); // Output: 1
console.log(tanh(0)); // Output: 0
console.log(asin(1)); // Output: 1.5707963267948966 (π/2)
console.log(acos(1)); // Output: 0
console.log(atan(1)); // Output: 0.7853981633974483 (π/4)
// Handle division by zero
try {
console.log(divide(6, 0));
} catch (error) {
console.error(error.message); // Output: Cannot divide by zero
}