use warnings; use strict; use Data::IEEE754::Tools qw(to_hex_floatingpoint to_dec_floatingpoint nextUp nextDown); use 5.022; # for %a printf "%-6.6s %30.30s %30.30s %30.30s %30.30s %30.30s\n", 'approx', '%30.16f', '%30.16e', '%a', 'to_hex_floatingpoint()', 'to_dec_floatingpoint()'; foreach my $v ( map { $_ / 10. } 0 .. 100, 1280, 10240) { # 0 .. 10, 128, 1024 my $d = nextDown($v); my $u = nextUp($v); printf "%-6.1f-ULP %30.16f %30.16e %30.13a %30.30s %30.30s\n", $v, $d, $d, $d, to_hex_floatingpoint($d), to_dec_floatingpoint($d); printf "%-6.1f %30.16f %30.16e %30.13a %30.30s %30.30s\n", $v, $v, $v, $v, to_hex_floatingpoint($v), to_dec_floatingpoint($v); printf "%-6.1f+ULP %30.16f %30.16e %30.13a %30.30s %30.30s\n", $v, $u, $u, $u, to_hex_floatingpoint($u), to_dec_floatingpoint($u); print "\n"; } printf "%-6.6s %30.30s %30.30s %30.30s %30.30s %30.30s\n", 'approx', '%30.16f', '%30.16e', '%a', 'to_hex_floatingpoint()', 'to_dec_floatingpoint()';