go ahead... be a heretic | |
PerlMonks |
Re: Math::FixedPrecision and bignum clashby thanos1983 (Parson) |
on Oct 08, 2014 at 12:58 UTC ( [id://1103171]=note: print w/replies, xml ) | Need Help?? |
Hello mje, I did a bit of a research as McA did but on a different area. I came up with the following: Ok let's start with the basics, I tried to load both Math::FixedPrecision and bignum. As a result, I got the same error with you. Then I went I start reading for bignum and I found this: All operators (including basic math operations) are overloaded. Integer and floating-point constants are created as proper BigInts or BigFloats, respectively. If you do use bignum; at the top of your script, Math::BigFloat and Math::BigInt will be loaded and any constant number will be converted to an object (Math::BigFloat for floats like 3.1415 and Math::BigInt for integers like 1234). So at this point I can imagine there is a conflict between the packages Math::FixedPrecision and bignum. So as a second step I decided to go through the documentation of Math::BigFloat and Math::BigInt where are used by bignum in order to create my solution to your problem. If I understand correctly, your problem is that you want to have accuracy to the nth digit of your float, but at the same time you want to use the bignum module. Update: I just thought that maybe you are interested in just getting the 2 digits after the dot of a float, without rounding. In that case the solution could be much more simpler by using substr. If this is what you are looking for you can simply do that: Update 2: wrong output, correcting output. I was experimenting and accidentally I posted before the experimentation.
Alternatively if my assumption is correct, sample of working code with the output:
Seeking for Perl wisdom...on the process of learning...not there...yet!
In Section
Seekers of Perl Wisdom
|
|