P is for Practical | |
PerlMonks |
Re: Decimal Array rangeby ikegami (Patriarch) |
on Dec 21, 2010 at 18:14 UTC ( [id://878331]=note: print w/replies, xml ) | Need Help?? |
You're thinking of something like BASIC's STEP clause, in effect. You can achieve this using a C-style loop:
but then you can end up with an accumulation of floating point error.*
The solution is to use an integer for the loop counter, and calculate the decimal number from it.
Now that you're using integers, you can use a cleaner syntax.
You already been shown how this get the numbers as a list.
* — A lot of numbers are periodic in binary. For example, 1/10 is perodic is binary, just like 1/3 is periodic in decimal. It would take infinite storage to store 1/10 as a floating point number.
In Section
Seekers of Perl Wisdom
|
|