POV-Ray : Newsgroups : povray.binaries.images : Strange behaviour of mod() : Re: Strange behaviour of mod() Server Time
7 Oct 2024 07:30:20 EDT (-0400)
  Re: Strange behaviour of mod()  
From: MichaelJF
Date: 21 Sep 2024 02:33:27
Message: <66ee68b7$1@news.povray.org>
Am 21.09.2024 um 04:21 schrieb Jörg "Yadgar" Bleimann:
> Hi(gh)!
> 
> For generating a time display for my current attempt at a Satisfactory 
> 1.0 speedrun, I use the following code:
> 
> #declare hours=div(clock,90000);
> #declare minutes=mod(div(clock,1500),60);
> #declare seconds=mod(div(clock,25),60);
> #declare centiseconds=mod(clock,25)*4;
> 
> and the text object is built like:
> 
>
concat(str(hours,-2,0),":",str(minutes,-2,0),"'",str(seconds,-2,0),",",str(centiseconds,-2,0)),0.001,0
> 
> But whenever the clock value is divisible by 25 without remainder, I get 
> "100" instead of "00" for the centiseconds part of the timestamp. Why?
> 
> See you in Khyberspace!
> 
> Yadgar
> 
Hi Yadgar,

mod() seems to affect only the integer part of a float value. E.g., 
mod(24.88248825,25)=24.88248825 and mod(25.00250053,25)=0.00250053.

The value of 100 comes from the rounding by str(value,-2,0). E.g.,
str(24.88248825*4,2,0)=str(99.52995300,-2,0)=100, as the fractional part 
is greater than 0.5.

Maybe

#declare centiseconds=floor(mod(clock,25)*4);

will serve you better.

Regards
Michael


Post a reply to this message

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