Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Re: (4) Dividing and formatby Ninthwave (Chaplain) |
on Nov 27, 2003 at 22:39 UTC ( [id://310615]=note: print w/replies, xml ) | Need Help?? |
No I missed a step that is all. The idea is to seperate the integers from the floating points. I had a good think on the train and I am sure it is mixing floating points and the int statement in the maths that is causing it. So the steps are multiply by ten to the power of decimal places plus one. Take an integer of this to drop all deimcals and add 5. Divide this number by ten. Take the integer of this. Divide the result by 10 to the power of decimal places. Well the test code I tried using that idea and got this. Even more weird.
So from that we modify the code so more.
Now the error is in the divide by ten and not the int function. So no matter what happens int of 1265 is returning 1264. We have something in the number Change 12650 to 12652 and the output is So it is not int that is the problem it is perls use of numbers.
The Perl Man Page says:
And there are modules to help, so the game of using maths to do this doesn't work without external help. So there is no bug outside of the limitation of computers as is, which I think we felt when doing this, but it is funny how this conversion under the hood can introduce errors in simple programming. Update:After reading Man on Modlib the integer will force integer maths instead of the standard double. So after alot of research and the obvious is now staring me in the face all maths in perl use double so you have to watch for binary fractions when you divide causing inmprecision. I am sure this was obvious to most some here but it was a revelation to me which means how good for me the original question was. I really like perlmonks this is such a better way to continue learning than just books and code.
"No matter where you go, there you are." BB
In Section
Seekers of Perl Wisdom
|
|