POV-Ray : Newsgroups : povray.newusers : mod() and floating point division woes. :( : Re: mod() and floating point division woes. :( Server Time
16 Apr 2024 10:15:18 EDT (-0400)
  Re: mod() and floating point division woes. :(  
From: Alain
Date: 3 Sep 2018 14:25:34
Message: <5b8d7c9e$1@news.povray.org>
Le 18-09-02 à 20:27, Bald Eagle a écrit :
> 
> So....
> 
> I _just_ want to use mod (N, 0.1) in a loop of #for(N, 0, 1, 0.02).
> 
> What's a good reliable way to implement an fmod() equivalent?
> Do I need to write a macro, or is there a straightforward function (){} that I
> can use?
> 
> Sorry to be grappling with "computer science math" again.
> Thus, I return to the newusers section.  :|
> 
> Some of the values I get are "0", others are "0.1".
> I'm challenged by the wide disparity between the two possibilities, and can't
> get anything to work reliably, especially when I try to use the mod(A, B) result
> in a select () statement.
> 
> 
> 

I would multiply everything by 10 or 100, calculate the mod(A,B), then 
divide by 10 or 100.

mod(A,B) stand for the remainder of an integer division. It don't play 
well with a non-integer divisor. At least, that's what I tend to assume.

You can use something like :
#declare Something = mod(N*10, 1)/10;

This is functionally identical to what you want.


Post a reply to this message

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