Created
January 21, 2016 19:14
-
-
Save p120ph37/efbcec1f74cacd0fe791 to your computer and use it in GitHub Desktop.
Demonstrates machine epsilon in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
my $val1; | |
if(($ARGV[0] // '') eq 'fixed') { | |
require Math::FixedPoint; | |
$val1 = Math::FixedPoint->new(2.1, 2); # fixed-point number | |
} else { | |
$val1 = 2.1; # floating point number | |
} | |
while($val1 * 10 == $val2) { | |
$val1 += 0.1; | |
$val2 += 1; | |
} | |
printf "Epsilon exceeded at (\$val1 = %0.16f) * 10 != (\$val2 = %d)\n", $val1, $val2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: