Package Exports
- adv_calculator
- adv_calculator/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (adv_calculator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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 ofaandb.subtract(a, b): Returns the difference whenbis subtracted froma.multiply(a, b): Returns the product ofaandb.divide(a, b): Returns the quotient whenais divided byb. Throws an error ifbis zero.exponential(base, exponent): Returns the result ofbaseraised to the power ofexponent.modulus(a, b): Returns the remainder whenais 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 ofaandb.lcm(a, b): Returns the lowest common multiple ofaandb.
Bitwise Functions
bitwiseAnd(a, b): Performs a bitwise AND operation onaandb.bitwiseOr(a, b): Performs a bitwise OR operation onaandb.bitwiseXor(a, b): Performs a bitwise XOR operation onaandb.bitwiseNot(a): Performs a bitwise NOT operation ona.leftShift(a, b): Performs a left bitwise shift onabybbits.rightShift(a, b): Performs a right bitwise shift onabybbits.zeroFillRightShift(a, b): Performs a zero-fill right shift onabybbits.
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.gitNavigate to the project directory:
cd adv_calculatorInstall 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
}