At 4:25 AM +0300 7/19/09, Octavian Râs¸nit¸a wrote:
From: "Dr.Ruud" <rvtol+use...@isolution.nl>
To me that means that you "don't get it" yet.
Oh yes I get it, but I don't like it.
No, you don't seem to understand. Perl, PHP, and
all other languages do floating-point arithmetic
using the built-in arithmetic provided by modern
CPUs. The difference between your sample Perl
code and PHP code is that the Perl code prints
out the numbers with more digits. If you were to
get PHP to print out more digits, you would see
that the result is the same. PHP is just hiding
the inaccuracies of representing decimal
fractions using binary numbers, because the
inaccuracy is insignificant in most applications.
What would be the problem if the way of doing
calculations by using bignum would be the
default?
Does it give errors? It would be helpful to know.
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.
It is stupid to penalize every program to
accomplish what only a very few programs need.
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.
--
Jim Gibson
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/