POV-Ray : Newsgroups : povray.advanced-users : Round function Server Time
24 Nov 2024 07:31:02 EST (-0500)
  Round function (Message 1 to 2 of 2)  
From: Woody
Subject: Round function
Date: 13 Nov 2007 12:55:00
Message: <web.4739e4827567ddbb94e61a50@news.povray.org>
Can someone help me,

I am trying to create a round(a,b) function. i.e something to take float a and
round it to b decimal places or round it to the nearest b

I need to be able to use it in an isosurface object as say

isosurface{
function{abs(x-round(x,0))}
}

where round(x,0) rounds to 0 decimal places.

I tried a macro like

#macro round(a,b)
val(str(a,64,b)
#end

pov doesnt handle the promotion properly

is there anyway I can construct a function to achieve the same effect?


Post a reply to this message

From: Trevor G Quayle
Subject: Re: Round function
Date: 13 Nov 2007 13:10:00
Message: <web.4739e80d58185619c150d4c10@news.povray.org>
"Woody" <nomail@nomail> wrote:
> Can someone help me,
>
> I am trying to create a round(a,b) function. i.e something to take float a and
> round it to b decimal places or round it to the nearest b
>
> I need to be able to use it in an isosurface object as say
>
> isosurface{
> function{abs(x-round(x,0))}
> }
>
> where round(x,0) rounds to 0 decimal places.
>
> I tried a macro like
>
> #macro round(a,b)
> val(str(a,64,b)
> #end
>
> pov doesnt handle the promotion properly
>
> is there anyway I can construct a function to achieve the same effect?

#declare Round=function
(a,b){select(a,-1,1)*int(abs(a)*pow(10,b)+0.5)/pow(10,b)}
rounds to the b decimal place (should handle negative numbers properly too).

-tgq


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.