/* gcd.pov -- greatest common divisor */ #version 3.7; global_settings {assumed_gamma 1} /* suppress "no objects" warning */ box {0,1} /* inputs from command-line, Wiki example o/wise */ #if (!defined(A)) #declare A = 48; #elseif (int(A) != A | 0 > A) #error "oops, 'A' must be positive integer." #end #if (!defined(B)) #declare B = 18; #elseif (int(B) != B | 0 > B) #error "oops, 'B' must be positive integer." #end /* "Euclidean algorithm", cf Wikipedia */ #macro m_gcd(a_,b_) #if (b_ >= a_) #error "oops, 'A' must be larger than 'B'." #end #local ta_ = a_; #local tb_ = b_; #while (tb_) #local v_ = mod(ta_,tb_); #local ta_ = tb_; #local tb_ = v_; #end ta_ #end #declare r_ = m_gcd(A,B); #debug concat("gcd(",str(A,0,0),",",str(B,0,0),") = ",str(r_,0,0),".\n")