]> gitweb.factorcode.org Git - factor.git/commitdiff
math: fix bug with ``0 0 lcm``
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 9 Sep 2023 00:52:24 +0000 (17:52 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 9 Sep 2023 00:52:24 +0000 (17:52 -0700)
core/math/math-docs.factor
core/math/math.factor

index 15f22b393ca598f0bbbc4649d1c4a4b8624380d9..e654f9b7aa605089afc339aac2a669a22a033d1c 100644 (file)
@@ -255,6 +255,8 @@ HELP: lcm
     { $example "USING: math prettyprint ;" "10 5 lcm ." "10" }
     { $example "USING: math prettyprint ;" "10 3 lcm ." "30" }
     { $example "USING: math prettyprint ;" "10 8 lcm ." "40" }
+    { $example "USING: math prettyprint ;" "10 0 lcm ." "0" }
+    { $example "USING: math prettyprint ;" "0 0 lcm ." "0" }
 } ;
 
 HELP: 2/
index 227ec70cb18c02133ad5be4865e2721828686b5f..3096af7f68c9e7477a2ee61a86e99139bf8472fa 100644 (file)
@@ -233,7 +233,7 @@ M: bignum simple-gcd bignum-gcd ; inline
 M: real simple-gcd gcd nip ; inline
 
 : lcm ( a b -- c )
-    [ * ] 2keep simple-gcd /i ; foldable
+    [ * dup zero? ] 2keep '[ _ _ simple-gcd /i ] unless ; foldable
 
 : fp-bitwise= ( x y -- ? ) [ double>bits ] same? ; inline