summaryrefslogtreecommitdiff
path: root/pod/perlfaq4.pod
diff options
context:
space:
mode:
authorBoyd, Brooks D <unknown>2003-09-11 22:38:19 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-09-13 06:47:23 +0000
commit32969b6e12eabd4800008f3f0270114b7962c5e1 (patch)
treeef28817ef773cc80a6bd01eb9fb151b1c352b9a0 /pod/perlfaq4.pod
parent363c40c40eaf5d0cfd92f460a3f838c41f9756ad (diff)
downloadperl-32969b6e12eabd4800008f3f0270114b7962c5e1.tar.gz
[perl #23788] int of a fraction errors
From: "Boyd, Brooks D" (via RT) <perlbug-followup@perl.org> Message-ID: <rt-23788-64511.8.7546744242259@rt.perl.org> Add a separate faq entry for int(). (Yes, a bit redundant with the existing "why are my numbers broken" entry.) p4raw-id: //depot/perl@21204
Diffstat (limited to 'pod/perlfaq4.pod')
-rw-r--r--pod/perlfaq4.pod18
1 files changed, 18 insertions, 0 deletions
diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod
index af08e473ee..e2054e49bd 100644
--- a/pod/perlfaq4.pod
+++ b/pod/perlfaq4.pod
@@ -28,6 +28,24 @@ L<"Floating Point Arithmetic"|perlop> for more details.
my $number = sprintf "%.2f", 10/3;
+=head2 Why is int() broken?
+
+Your int() is most probably working just fine. It's the numbers that
+aren't quite what you think.
+
+First, see the above item "Why am I getting long decimals
+(eg, 19.9499999999999) instead of the numbers I should be getting
+(eg, 19.95)?".
+
+For example, this
+
+ print int(0.6/0.2-2), "\n";
+
+will in most computers print 0, not 1, because even such simple
+numbers as 0.6 and 0.2 cannot be presented exactly by floating-point
+numbers. What you think in the above as 'three' is really more like
+2.9999999999999995559.
+
=head2 Why isn't my octal data interpreted correctly?
Perl only understands octal and hex numbers as such when they occur as