POV-Ray : Newsgroups : povray.general : Random numbers and rounding Server Time
3 Aug 2024 02:23:34 EDT (-0400)
  Random numbers and rounding (Message 1 to 4 of 4)  
From: Vladimir
Subject: Random numbers and rounding
Date: 22 Jun 2004 14:10:01
Message: <web.40d874dae913f9c9de2762960@news.povray.org>
Is there any way to round a float to the nearest whole number. It may seem
like a stupid question but i have been trying with int() and failing
dismally.
Thanks


Post a reply to this message

From: Slime
Subject: Re: Random numbers and rounding
Date: 22 Jun 2004 14:22:16
Message: <40d878d8@news.povray.org>
> Is there any way to round a float to the nearest whole number.

I'm not sure why there's no round() function, but here, this should work:

#macro round(x)
floor(x+0.5)
#end

(floor() is like int() except that it always rounds towards negative
infinity, whereas int() rounds towards zero. The + 0.5 causes the transition
from one integer to another to occur when x passes by something-and-a-half.)

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: ABX
Subject: Re: Random numbers and rounding
Date: 22 Jun 2004 14:46:12
Message: <gfvgd0ls77pnc48mj9dshmrfcouql4c9vb@4ax.com>
On Tue, 22 Jun 2004 14:22:07 -0400, "Slime" <fak### [at] emailaddress> wrote:
> > Is there any way to round a float to the nearest whole number.
>
> I'm not sure why there's no round() function, but here, this should work:
>
> #macro round(x)
> floor(x+0.5)
> #end

IMO

#declare round=function(x){floor(x+0.5)};

would be better.

ABX


Post a reply to this message

From: Warp
Subject: Re: Random numbers and rounding
Date: 22 Jun 2004 15:32:03
Message: <40d88933@news.povray.org>
ABX <abx### [at] abxartpl> wrote:
> IMO

> #declare round=function(x){floor(x+0.5)};

> would be better.

  Don't know about better, but at least it's much faster. :)

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

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