From: "Jim Gibson" <jimsgib...@gmail.com>
PHP is just hiding the inaccuracies of representing decimal fractions
using binary numbers, because the inaccuracy is insignificant in most
applications.
Well, if it wouldn't be significant, why would PHP hide that inaccuracy as a
default? Why doesn't Perl do the same thing?
Using Bignum means doing arithmetic with more than 64 bits. 64-bit
floating-point numbers are 1) accurate enough for almost all applications
and 2) supported by hardware, which means they are very fast. Using more
bits for more accuracy means the arithmetic cannot be done with hardware
instructions alone, but must be done with multiple instructions in
software. As a result, the calculations will take an order of magnitude
longer.
Well, in that case Perl could use the same way PHP uses.
The calculations made with PHP are faster even if PHP also need to also hide
that inaccuracy.
It is stupid to penalize every program to accomplish what only a very few
programs need.
It is true, and maybe I am wrong because I need to do many calculations
using money, but if "most of the programs" wouldn't need this inaccuracy
hiding, why PHP, Oracle, PostgreSQL and MySQL use this way of hinding the
inaccuracy automaticly?
I don't want to say that if Windows is used by most users this means that it
is the best. They all could be wrong and perl good, but the reality is that
a perl programmer would need to do more manual coding than a PHP programmer
and this is what I don't like. It is not that I don't know how to do it, but
the solutions are either not nice or very slow, while the solution found by
PHP is very fast and it doesn't imply other things than just making the
calculation.
The solution has been given to you: print out floating-point numbers with
the appropriate number of digits using printf and the format descriptor
"%.mf", where m is the number of digits you want. If you actually need
more than 64 bits (and you probably don't), then use Math::BigFloat and
suffer the performance penalty.
True. I don't need more than 4 or 8 digits, but I don't know how to do this
transparently without needing to use sprintf() for each calculation.
I started to study how I could create a module that overloads the operators
that could do this kind of calculation, exactly like bignum does, and just
use sprintf() in that module, but for the moment I found only how to
overload the constants, not the operation with constants.
Octavian
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/