<# xmToString(i, m) #> <# n := i #> <# r := "" #> <# #> <# // This macro will take an integer i and return a #> <# // string that looks like i * m. This #> <# // might be useful i * m is a number larger than #> <# // 32 bits can hold. #> <# #> <# // The "trick" is to do the multiplication "by hand" #> <# // one digit at a time, managing the carry, etc. #> <# #> <# while(n > 0 || carry > 0) #> <# n_lsd := n%10 #> <# d := n_lsd * m + carry #> <# if (d > 9) #> <# unit := d%10; carry := d - unit; carry := carry/10; d := unit #> <# else #> <# carry := 0 #> <# endif #> <# r := d $ r #> <# // setoutput console; "(n, n_lsd, d, carry, r): " $ n $ " " $ n_lsd $ " " $ d $ " " $ carry $ " " $ r $ "\n"; endsetoutput #> <# n := n - n_lsd; n := n/10 #> <# endwhile #> <# #> <# return(r) #> <# #> <# endtmpl #> <# _xmToString(i, m) #> <# // Tester nacro #> <# #> <# setoutput console #> <# r := tmpl.xmToString(i, m); r $ "\n" #> <# endsetoutput #> <# #> <# endtmpl #>