mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(mathutil): divide before multiplying LCM factors (#363)
This commit is contained in:
1 parent
145959ee62
commit
0f4f73fbba
2 files changed
+8
-1
No files matched your search
@@ -368,7 +368,7 @@ func lcm[T constraints.Integer](a, b T) T {
|
||||
if a == 0 || b == 0 {
|
||||
panic("lcm function: provide non zero integers only.")
|
||||
}
|
||||
return a * b / gcd(a, b)
|
||||
return a / gcd(a, b) * b
|
||||
}
|
||||
|
||||
// Cos returns the cosine of the radian argument.
|
||||
|
||||
@@ -17,6 +17,13 @@ func TestExponent(t *testing.T) {
|
||||
assert.Equal(int64(100), Exponent(10, 2))
|
||||
}
|
||||
|
||||
func TestLCMIntermediateOverflow(t *testing.T) {
|
||||
assert := internal.NewAssert(t, "TestLCMIntermediateOverflow")
|
||||
assert.Equal(uint8(32), LCM(uint8(32)))
|
||||
assert.Equal(uint8(192), LCM(uint8(64), uint8(96)))
|
||||
assert.Equal(uint64(1<<40), LCM(uint64(1<<40), uint64(1<<39)))
|
||||
}
|
||||
|
||||
func TestFibonacci(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in new issue
Block a user