in reply to Determining the minimum representable increment/decrement possible?
To put it glibly, we just need to increase/decrease the value by one ULP.use strict; use warnings; use Math::MPFR qw(:mpfr); # Set $prec and $out_prec appropriately my $prec = 53; # NV has 53-bit significand # my $prec = 64; # NV has 64-bit significand # my $prec = 106; # NV has 106-bit significand # my $prec = 113; # NV has 113-bit significand Rmpfr_set_default_prec($prec); my $str1 = '1.9041105342991877e+258'; my $str2 = '-8.2727285363069939e-293'; my $obj1 = Math::MPFR->new($str1); my $obj2 = Math::MPFR->new($str2); Rmpfr_nextbelow($obj1); Rmpfr_nextabove($obj2); print "$obj1\n$obj2\n"; # To convert the objects to NVs: my $nv1 = Rmpfr_get_NV($obj1, MPFR_RNDN); my $nv2 = Rmpfr_get_NV($obj2, MPFR_RNDN); my $out_prec = 17; # 53-bit significand # my $out_prec = 21; # 64-bit significand # my $out_prec = 33; # 106-bit significand # my $out_prec = 36; # 113-bit significand $out_prec--; printf "%.${out_prec}e\n%.${out_prec}e\n", $nv1, $nv2; __END__ Outputs: 1.9041105342991875e258 -8.2727285363069927e-293 1.9041105342991875e+258 -8.2727285363069927e-293
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Determining the minimum representable increment/decrement possible?
by syphilis (Archbishop) on Jun 16, 2016 at 09:47 UTC |