Re: Variable $i count a lot numbers...
- From: chas.owens@xxxxxxxxx (Chas Owens)
- Date: Sun, 2 Sep 2007 03:11:47 -0400
On 9/1/07, Rodrigo Tavares <digolinopage@xxxxxxxxxxxx> wrote:
snip
Write a number:23snip
Value i is : 1081
23
11.5
5.75
2.875
1.4375
Why did script show the value ?
The counter must be six.
Sounds like you want integer math rather than floating point math. In
floating point math repeatedly halving the value will only reach 0
when the value becomes so small that it can't fit in your floating
point representation. In real math it never reaches 0, it just
becomes infinitely close to zero. You can get integer math for the
current lexical scope by saying
use integer;
You can also use the int function judiciously to achieve the same
effect (albeit without the performance gain). If you want a close
approximation of real math you can say
use bignum;
or
#my understanding is that this is both faster and harmless to try
since it will use
#the default if it can't find the GMP library
use bignum lib => 'GMP';
Your loop will only end when your machine crashes (or kills the
process) due to there not being enough memory to store the number.
.
- References:
- Variable $i count a lot numbers...
- From: Rodrigo Tavares
- Variable $i count a lot numbers...
- Prev by Date: Re: Parsing qmail-qread data
- Next by Date: Re: cgi app runtime unique identifier.
- Previous by thread: Re: Variable $i count a lot numbers...
- Index(es):
Relevant Pages
|