POV-Ray : Newsgroups : povray.general : large numbers turn random negative!? : Re: large numbers turn random negative!? Server Time
20 May 2024 14:15:13 EDT (-0400)
  Re: large numbers turn random negative!?  
From: kurtz le pirate
Date: 25 Jul 2023 04:32:14
Message: <64bf888e$1@news.povray.org>
On 24/07/2023 20:27, Leroy wrote:
> I have pov3.7 on my winXP.
> While playing around with making music using POV. I made long rhythm strings
> and turn them into numbers and visa versa. Using random numbers to check things
> out, when negative random numbers show up. With NO negative numbers on the page.
> It's not a big deal in my case. But I wonder if this is a window thing, or a
> float thing in POV,and if anyone else came a cross this.

Window thing : no.
Float thing in POV : yes and no !

In fact, as is often the case, we come back to the
interpretation/implementation of the int() function
with binaries representation of floating point numbers
in 32 or 64 bits.


Try this piece of code :

#declare r = rand(S);
#debug concat("rand(S)           = ",str(r,0,-1),"\n")
#declare Mv=r*Cv;
#debug concat("rand(S)*Cv        = ",str(Mv,0,-1),"\n")
#declare Mv1 = int(Mv);
#debug concat("int(rand(S)*Cv)   = ",str(Mv1,0,0),"\n")
#declare Mv2 = floor(Mv);
#debug concat("floor(rand(S)*Cv) = ",str(Mv2,0,0),"\n")

And the results are :

rand(S)           = 0.501773
rand(S)*Cv        = 551705517183.952148
int(rand(S)*Cv)   = -2147483648
floor(rand(S)*Cv) = 551705517183



Have fun too with https://baseconvert.com/ieee-754-floating-point



-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

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