POV-Ray : Newsgroups : povray.general : Few tricks : Few tricks Server Time21 Apr 2024 03:46:39 EDT (-0400)
 Few tricks
 From: kurtz le pirate Date: 26 Nov 2023 04:46:56 Message: <65631410\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#65631410%241%40news.povray.org",
"dateCreated": "2023-11-26T09:46:56+00:00",
"datePublished": "2023-11-26T09:46:56+00:00",
"author": {
"@type": "Person",
"name": "kurtz le pirate"
}
}
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.