POV-Ray : Newsgroups : povray.newusers : mod() and floating point division woes. :( : Re: mod() and floating point division woes. :( Server Time 2 Mar 2024 21:37:12 EST (-0500)
 Re: mod() and floating point division woes. :(
 From: Alain Date: 3 Sep 2018 14:25:34 Message: <5b8d7c9e\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#5b8d7c9e%241%40news.povray.org",
"headline": "Re: mod() and floating point division woes. :(",
"dateCreated": "2018-09-03T18:25:34+00:00",
"datePublished": "2018-09-03T18:25:34+00:00",
"author": {
"@type": "Person",
"name": "Alain"
}
}
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.
>
> 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.
```