Skip to content

Instantly share code, notes, and snippets.

@SineSwiper
Created October 9, 2012 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SineSwiper/3859539 to your computer and use it in GitHub Desktop.
Save SineSwiper/3859539 to your computer and use it in GitHub Desktop.
t/06virtual.i near replacement
sub near ($$$) {
my ($got, $expect, $test) = @_;
my $d = $expect ? abs($got/$expect - 1) : abs($got);
local $Test::Builder::Level = $Test::Builder::Level + 1;
$expect =~ /nan/i ?
ok( $got eq $expect, $test) || diag("NaN is? $got ~= $expect") :
cmp_ok($d, '<', $eps, $test) || diag("near? $got ~= $expect");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment