Q:

How to avoid generating a very small computational error in perl

my $a = 243300;
my $b = 3000;
my $c = 81.10;

if (($a - $b * $c) != 0) {
    warn "delta is " . ($a - $b * $c);
} else {
    print "OK\n";
}

The result produces a very small difference as:
Mac: ~ # perl f.pl
delta is 2.91038304567337e-11 at f.pl line 6.

I can work-around by comparing with 0.01 but how to avoid such problem and how come the very small difference?

A:

You could use an arbitrary-precision numerical package like Math::BigRat,Math::BigFloat, or Math::Decimal, but this will come with a significant performance penalty. 
use Math::Decimal qw(dec_sub dec_mul);
my ($a,$b,$c,$delta);
$a = 243300;
$b = 3000;
$c = 81.10;
$delta = dec_sub($a, dec_mul($b,$c));
if ($delta != 0) {
    warn "delta [M::D]is $delta\n";
} else {
    print "OK [M::D]\n";
}

use Math::BigRat;
$a = Math::BigRat->new(243300);
$b = Math::BigRat->new(3000);
$c = Math::BigRat->new(81.10);
$delta = $a - $b * $c;
if ($delta != 0) {
    warn "delta [M::BR]is $delta\n";
} else {
    print "OK [M::BR]\n";
}

