|
|
kurtz le pirate <kur### [at] gmailcom> wrote:
> 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
>
Yep, the 'floor' thing works as expected.
I got use to use 'int' for every thing & don't use 'floor' or 'ceil' hardly at
all.(I had to look up 'ceil' to place it here)
Awhile back I was hacking some MTS video files. So I checked our how floats
where stored. It's a bit complicated, but the main thing I remembered is that it
starts with a sign bit. I just couldn't see how that got changed. Now I can see
a way. Dealing with C++ I've had some problems with signed and unsigned
integers.
Thanks for your fix I'll have to remember it.
Have fun!!
Post a reply to this message
|
|