Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lua > JS
  • Loading branch information
appgurueu authored Jul 27, 2022
commit 734d1058f97306747753d79ac6e72bc6461f9e5b
7 changes: 5 additions & 2 deletions Maths/GetEuclidGCD.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ export function GetEuclidGCD(a, b) {
if (typeof a !== 'number' || typeof b !== 'number') {
throw new TypeError('Arguments must be numbers')
}
a, b = Math.abs(a), Math.abs(b)
a = Math.abs(a)
b = Math.abs(b)
if (a === 0 && b === 0) return undefined // infinitely many numbers divide 0
if (a < 0) a = -a
if (b < 0) b = -b
while (b !== 0) {
a, b = b, a % b
const rem = a % b
a = b
b = rem
}
return b
}