Chapter 9. Unreal Numbers
Tom Phoenix
God created the integers, all else is the work of man.
—Leopold Kronecker, 1823–1891
Out of a possible 99 points on a professor’s final exam, one student, the worst in the class, scored only 47. She marked the student’s test 47.4747…, since that’s 47/99. Another student got 83 correct, so she wrote 83.8383… at the top. But when she found that one student had gotten all 99 correct, she wrote 99.9999… on the exam. After a moment’s reflection, she added, “Although I can find nothing at fault with your answers, somehow you seem to have fallen a little short of perfection!”
A Surprising Program
Consider another scenario. Your manager brings this program to you:
#!/usr/bin/perl -w # See whether Perl can add? use strict; my $total = 19.08 + 2.01; my $expected_total = 21.09; print "The total is \$$total\n"; print "The expected total is \$$expected_total\n"; if ($total == $expected_total) { print "They are equal.\n"; } else { print "They aren't equal.\n"; }
Because when he ran it, this is what he saw:
The total is $21.09 The expected total is $21.09 They aren't equal.
Even if you don’t see this result on your computer, there is a similar program that demonstrates the same bizarre behavior.
Your manager wants you to stop using Perl, since you’re developing a financial application and it looks like Perl has serious bugs in its ability to handle basic arithmetic.
One of your co-workers pops in to say that he can fix that program. In a moment, he’s recoded the comparison ...
Get Computer Science & Perl Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.