Skip to content

Commit 07c5833

Browse files
committed
implement PGF gcd
1 parent 223b445 commit 07c5833

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/LaTeXML/Package/pgfmath.code.tex.ltxml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,12 @@ BEGIN {
613613
factorial => sub { pgfmathfactorial($_[0]); },
614614
floor => sub { floor($_[0]); },
615615
frac => sub { $_[0] < 0 ? ceil($_[0]) - $_[0] : $_[0] - floor($_[0]); },
616-
# gcd => sub { },
616+
gcd => sub {
617+
# PGF computes the gcd of the underlying TeX integers!
618+
my ($a, $b) = (abs($_[0]) * 65536, abs($_[1]) * 65536);
619+
($a, $b) = ($b, $a) if $b > $a;
620+
while ($b > 0) { ($a, $b) = ($b, $a % $b); }
621+
int($a / 65536); },
617622
# height => sub { },
618623
hex => sub { sprintf("%x", $_[0]); },
619624
Hex => sub { sprintf("%X", $_[0]); },

0 commit comments

Comments
 (0)