From 9ad679573c99b62e751d827be2d6b391cae52b6e Mon Sep 17 00:00:00 2001 From: hjp Date: Thu, 1 Oct 2009 17:29:22 +0000 Subject: [PATCH] script to compute ulp+ and ulp- --- ieeefloat/ulp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 ieeefloat/ulp diff --git a/ieeefloat/ulp b/ieeefloat/ulp new file mode 100755 index 0000000..4b2660d --- /dev/null +++ b/ieeefloat/ulp @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +my $x = $ARGV[0] + 0; + +my $d = 1; +while ($x + $d == $x) { + $d *= 2; +} +while ($x + $d/2 != $x) { + $d /= 2; +} + +printf "ulp+ = %.17e %.17e %.17e\n", $d, $x, $x + $d; + +$d = 1; +while ($x - $d == $x) { + $d *= 2; +} +while ($x - $d/2 != $x) { + $d /= 2; +} + +printf "ulp- = %.17e %.17e %.17e\n", $d, $x, $x - $d;