Skip to content

Commit

Permalink
v0.0.3 - trigonometry
Browse files Browse the repository at this point in the history
  • Loading branch information
kry008 committed Apr 4, 2023
1 parent 63eaa06 commit 7a9342c
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
98 changes: 98 additions & 0 deletions class/basicMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,104 @@ class BasicMath
}
return {a: a, b: b, result: sum};
}
logarithm(a)
{
if(a == 0)
{
return {a: a, result: "Cannot divide by zero"};
}
if(a == 1)
{
return {a: a, result: "Cannot divide by zero"};
}
if(a == -1)
{
return {a: a, result: "Cannot divide by zero"};
}
return {a: a, result: Math.log(a)};
}
factorial(a)
{
if(a == 0)
{
return {a: a, result: 1};
}
let sum = 1;
for (var i = 1; i <= a; i++)
{
sum *= i;
}
return {a: a, result: sum};
}
mathRoot(base, root = 2)
{
if(base == 0)
{
return {base: base, root: root, result: 0};
}
if(root < 0)
{
return {base: base, root: root, result: "Cannot divide by zero"};
}
if(root == 0)
{
return {base: base, root: root, result: "Cannot divide by zero"};
}
if(base < 0)
{
return {base: base, root: root, result: "Cannot divide by zero"};
}
return {base: base, root: root, result: Math.pow(base, 1/root)};
}
sinDegrees(a)
{
if(a == 0)
{
return {a: a, result: 0};
}
return {a: a, result: Math.sin(a * Math.PI / 180)};
}
cosDegrees(a)
{
if(a == 0)
{
return {a: a, result: 1};
}
return {a: a, result: Math.cos(a * Math.PI / 180)};
}
tanDegrees(a)
{
if(a == 0)
{
return {a: a, result: 0};
}
return {a: a, result: Math.tan(a * Math.PI / 180)};
}
sinRadians(a)
{
if(a == 0)
{
return {a: a, result: 0};
}
return {a: a, result: Math.sin(a)};
}
cosRadians(a)
{
if(a == 0)
{
return {a: a, result: 1};
}
return {a: a, result: Math.cos(a)};
}
tanRadians(a)
{
if(a == 0)
{
return {a: a, result: 0};
}
return {a: a, result: Math.tan(a)};
}


}

Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ console.log(math_basicMath.division(1, 0, 3));
console.log(math_basicMath.division(1, 0, 3).result);
console.log(math_basicMath.division([1, 2, 0]));
console.log(math_basicMath.division([1, 2, 0]).result);
console.log(math_basicMath.sinDegrees(-9).result);

0 comments on commit 7a9342c

Please sign in to comment.