Change 21204: [perl #23788] int of a fraction errors

[email protected] (Jarkko Hietaniemi)
Newsgroups perl.perlfaq.workers,perl.perl5.changes
Message-ID <[email protected]>
Change 21204 by jhi@kosh on 2003/09/13 06:47:23

	Subject: [perl #23788] int of a fraction errors 
	From: "Boyd, Brooks D" (via RT) <[email protected]>
	Date: 11 Sep 2003 22:38:19 -0000
	Message-ID: <[email protected]>
	
	Add a separate faq entry for int().  (Yes, a bit redundant
	with the existing "why are my numbers broken" entry.)

Affected files ...

... //depot/perl/pod/perlfaq4.pod#86 edit

Differences ...

==== //depot/perl/pod/perlfaq4.pod#86 (text) ====
Index: perl/pod/perlfaq4.pod
--- perl/pod/perlfaq4.pod#85~20981~	Mon Sep  1 04:28:35 2003
+++ perl/pod/perlfaq4.pod	Fri Sep 12 23:47:23 2003
@@ -28,6 +28,24 @@
 
 	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
End of Patch.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.