@rgsoft/math
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -171,3 +171,9 @@ declare class Complex { | ||
declare function mod(n: number, m: number): number; | ||
/** | ||
* Gets the greatest common divisor | ||
* @param { number } a | ||
* @param { number } b | ||
*/ | ||
declare function gcd(a: number, b: number): number; | ||
export { Complex, Line, Segment, Vector, mod }; | ||
export { Complex, Line, Segment, Vector, gcd, mod }; |
@@ -27,2 +27,3 @@ "use strict"; | ||
Vector: () => Vector, | ||
gcd: () => gcd, | ||
mod: () => mod | ||
@@ -405,3 +406,3 @@ }); | ||
// src/modulo.ts | ||
// src/number.ts | ||
function mod(n, m) { | ||
@@ -416,2 +417,17 @@ if (!Number.isInteger(n)) { | ||
} | ||
function gcd(a, b) { | ||
if (!Number.isInteger(a) || a <= 0) { | ||
throw new Error("Both numbers must be positive integers"); | ||
} | ||
if (!Number.isInteger(b) || b <= 0) { | ||
throw new Error("Both numbers must be positive integers"); | ||
} | ||
let d; | ||
do { | ||
d = Math.abs(a - b); | ||
a = Math.min(a, b); | ||
b = d; | ||
} while (d !== a && d > 0); | ||
return d; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -423,4 +439,5 @@ 0 && (module.exports = { | ||
Vector, | ||
gcd, | ||
mod | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@rgsoft/math", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Yet another JS math library", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -249,2 +249,23 @@ # math-js | ||
The `mod` function will fail if it receives a negative modulo or any non-integer | ||
number. | ||
number. | ||
## Greatest Common Divisor | ||
The `gcd` function calculates greatest common divisor between to positive | ||
integers | ||
```javascript | ||
console.log(gcd(18, 4)); | ||
``` | ||
will ouput `2`. | ||
## Least Common Multiple | ||
The `lcm` function calculates least common multple between to positive integers | ||
```javascript | ||
console.log(lcm(18, 4)); | ||
``` | ||
will ouput `36`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
70961
1007
270