Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add gmp_lcm()
Exposes mpz_lcm() and mpz_lcm_ui() for calculating the least common multiple. We already expose the somewhat complementary gmp_gcd() function.
- Loading branch information
Showing
with
57 additions
and 0 deletions.
- +1 −0 NEWS
- +1 −0 UPGRADING
- +9 −0 ext/gmp/gmp.c
- +1 −0 ext/gmp/php_gmp.h
- +45 −0 ext/gmp/tests/gmp_lcm.phpt
@@ -0,0 +1,45 @@ | ||
--TEST-- | ||
gmp_lcm(): Least common multiple | ||
--FILE-- | ||
<?php | ||
|
||
var_dump(gmp_lcm(100, 77)); | ||
var_dump(gmp_lcm(99, 77)); | ||
var_dump(gmp_lcm(99, -77)); | ||
var_dump(gmp_lcm(-99, -77)); | ||
|
||
var_dump(gmp_lcm(gmp_init(99), gmp_init(77))); | ||
|
||
var_dump(gmp_lcm(93, 0)); | ||
var_dump(gmp_lcm(0, 93)); | ||
|
||
?> | ||
--EXPECT-- | ||
object(GMP)#1 (1) { | ||
["num"]=> | ||
string(4) "7700" | ||
} | ||
object(GMP)#1 (1) { | ||
["num"]=> | ||
string(3) "693" | ||
} | ||
object(GMP)#1 (1) { | ||
["num"]=> | ||
string(3) "693" | ||
} | ||
object(GMP)#1 (1) { | ||
["num"]=> | ||
string(3) "693" | ||
} | ||
object(GMP)#3 (1) { | ||
["num"]=> | ||
string(3) "693" | ||
} | ||
object(GMP)#3 (1) { | ||
["num"]=> | ||
string(1) "0" | ||
} | ||
object(GMP)#3 (1) { | ||
["num"]=> | ||
string(1) "0" | ||
} |