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

In reply to Re: Determining the minimum representable increment/decrement possible? by syphilis
in thread Determining the minimum representable increment/decrement possible? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.