POV-Ray : Newsgroups : povray.newusers : rounding and logic functions : Re: rounding and logic functions Server Time
7 May 2024 20:36:53 EDT (-0400)
  Re: rounding and logic functions  
From: clipka
Date: 2 Aug 2013 01:52:36
Message: <51fb4924$1@news.povray.org>
Am 02.08.2013 06:54, schrieb Bald Eagle:
>
> I was plotting some data, (Version 3.6) and I had a lot of trouble getting
> otherwise programmatically simple goals accomplished.
>
> I see there are ceil() and floor() directives, though these seem suspect.

What's wrong with them?


> There's mod(), the definition of which in the manual seems ... odd.
> a remainder ought to be (A/B) - int(A/B)

That would be the fractional part of a division result, not the remainder.

Suppose you have ten pieces of cake, you have to split them fairly among 
three children, and cutting a piece into smaller ones is not an option. 
What's the result? Of course each child gets three pieces of cake, with 
one piece of cake /remaining/. Hence, an integer division of 10/3 yields 
3, and a /remainder/ of 1.

> But the manual says that this is them multiplied by B
> Maybe I'm just ignorant abut the definition of "modulus", but then the textual
> definition in the manual is misleading.

What's misleading about that? The formula given is unambiguous, the 
statement that mod(A,B) gives the value of A modulo B is straightforward 
(and true), and the statement that it returns the remainder after the 
integer division of A/B is also simple and true.


> Is there no simple ROUND() function?  To round a number to Q decimal places?

You can achieve a round-to-nearest-integer using ceil(X-0.5); You can 
achieve a round-to-Q-decimal-places by multiplying before and dividing 
after, such as in:

     ceil( X*pow(10,Q) - 0.5 ) * pow(0.1,Q)


> Also, how do I perform an OR comparison?
>
> IF (X = A _OR_ B)?

simple - just perform two individual comparisons and apply the OR 
operator ("|"):

#if ((x = a) | (x = b))


Post a reply to this message

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