POV-Ray : Newsgroups : povray.advanced-users : Max-value with function int() : Re: Max-value with function int() Server Time
29 Jul 2024 00:35:58 EDT (-0400)
  Re: Max-value with function int()  
From: Will W
Date: 14 May 2003 10:30:29
Message: <3ec25305@news.povray.org>
This snippet also shows what is happening, perhaps more clearly:

#declare r = pow(2,31) - 3;
#declare i = int(r);
#while (i>0)
   #declare r = r + 1;
   #declare i = int(r);
   #debug concat("r = ", str(r,0,-1), ";  int(r) = ", str(i,0,-1), "\n")
#end

This produces the following three lines in the Messages pane (with POV-Ray
3.5 on WinXP):

r = 2147483646.000000;  int(r) = 2147483646.000000
r = 2147483647.000000;  int(r) = 2147483647.000000
r = 2147483648.000000;  int(r) = -2147483648.000000

So, this demonstrates this implementation of POV represents integers with a
32 bit number wheel, that wraps from positive to negative values at 2 raised
to the 31st power (2^31, 2**31, or pow(2,31). This is of course because the
high order bit is used as a sign bit.

Suggestions:

Anyone working with large numbers should be made aware that POV maps all
real numbers to this number wheel when the int( ) function is used;

This awareness could be made available by modifying the entry for the int( )
function in the POV manual;

It would be nice to suggest a good alternative for persons whose work is
affected by this. It would be helpful if this was also included in the
manual.

An alternative that should work in all cases is

// given an original float f of unknown magnitude that might exceed the
limits of the int( ) function
#declare tmp = floor ( abs( f ) );
#declare f = ( f > 0 ? tmp : -tmp);

(Above is untested; beware possible typos, etc, and perhaps others should
check my logic)


--
Will Woodhull
Thornhenge, SW Oregon, USA
willl.at.thornhenge.net


PS-- it should be noted that the size of the number wheel that int( ) uses
is compiler dependent. The limit will probably be 2^63 on the newer machines
that are coming out, and probably 2^15 on antiques using 8086 code.




"Jaap Frank" <jjf### [at] xs4allnl> wrote in message
news:3ec1797c$1@news.povray.org...
> Hello,
>
> when I was testing how I can translate a float like
>
> 1.23456789e-28
>
> into a 6 bytes notation for a ppm file I noticed that
> the float function int() has a maximum value.
> Try this:
>
> *************************************
> #declare Num1 = pow(2,30);
> #declare Num2 = pow(2,31);
> #declare Num3 = pow(2,32);
> #declare Int1 = int(Num1);
> #declare Int2 = int(Num2);
> #declare Int3 = int(Num3);
> #debug concat("\nNum1 = ",str(Num1,0,-1),
>        " | Num2 = ",str(Num2,0,-1),
>        " | Num3 = ",str(Num1,0,-1))
> #debug concat("\nInt1 = ",str(Int1,0,-1),
>        " | Int2 = ",str(Int2,0,-1),
>        " | Int3 = ",str(Int3,0,-1),"\n")
> *************************************
> The result for me was:
>
> Persistence of Vision(tm) Ray Tracer Version 3.5 win32 (.icl)
> ....
> Num1 = 1073741824.000000 | Num2 = 2147483648.000000 | Num3 =
1073741824.000000
> Int1 = 1073741824.000000 | Int2 = -2147483648.000000 | Int3
= -2147483648.000000
>
> There is no warning about a max value in the manual.
> Maybe it is wise to do this.
>
> Jaap Frank
>
>


Post a reply to this message

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