in reply to Determining the minimum representable increment/decrement possible?

Firstly, don't assume that perl will assign either of those values correctly. At around those precisions, it's not uncommon for perl to assign values that are off by (up to) a few ULPs.

I would do it with Math::MPFR (though the real credit goes to the mpfr library):
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
To put it glibly, we just need to increase/decrease the value by one ULP.

Cheers,
Rob
  • Comment on Re: Determining the minimum representable increment/decrement possible?
  • Download Code

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
    At around those precisions ...

    I meant "At around those exponents... ".

    I would have made this correction as an update to the original post .... but the option to make that update is seemingly currently unavailable.

    UPDATE: hippo has just pointed me to the thread where this recent change (which occurred while I was away) was discussed.
    ++ to BrowserUk for pushing for the option to re-instate the update box to its original location and ++ to jdporter for enabling that option.

    Cheers,
    Rob