|
 |
Hello,
In my current project, I'm doing a lot of calculations using macros and
functions. I need macros that return several values and a rounding
function. I'm sharing my solutions here (which may already be known to
the Grand Masters).
*** Tips 1 : Rounding ***
#declare pow10 = function(num_digits) {
prod(i,1,num_digits,10)
}
#declare fnRound = function (number, num_digits) {
ceil(number*pow10(num_digits))/pow10(num_digits)
}
#declare a = fnRound(pi,6); // round pi to 6 digits
#debug concat(str(a,0,9),"\n")
-> 3.141 593 000 (extra spaces added)
Waring : Be careful with the number of digits required, depending on the
precision of the calculations... especially with large numbers.
*** Tips 2 : Multiple return values from macro directly assigned to
variables ***
#declare MyMacro(p1, p2, p3, p4)
..
..
array { Return1, Return2, Return3}
#end
Used in this way :
#declare { V1, V2, V3 } = MyMacro (a, b, c, d);
I hope this helps.
Critical comments welcome !
--
Kurtz le pirate
Compagnie de la Banquise
Post a reply to this message
|
 |