good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: limit of for loop!!by GrandFather (Saint) |
on Jan 01, 2012 at 21:41 UTC ( [id://945810]=note: print w/replies, xml ) | Need Help?? |
What are you actually trying to do? What precision (how many digits) do you really need? Moritz provided a good solution (work with integer values then scale as the last step) - what is wrong with that solution? As an exercise try writing 1/3 as a decimal fraction in full. Let me get you started:
Have you figured out that you can't exactly represent 1/3 as a finite decimal fraction? In the same way you can't exactly represent 1/10 (base 10) as a finite binary fraction. This seems like a problem, but for almost all real applications for arithmetic it is not an issue. You seldom need more than a few digits of precision for an answer (although for some calculations you may need more precision for intermediate answers). So the key questions are: what are you trying to do and how much precision do you really need? There are many possible ways to solve your problem, but a solution depends very much on what you are trying to achieve.
True laziness is hard work
In Section
Seekers of Perl Wisdom
|
|