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

For an Inline::C solution, the following works ok for me with gcc on Windows:
use strict; use warnings; use Inline C => Config => BUILD_NOISY => 1, ; use Inline C => <<'EOC'; double nxtafter(double in, double dir) { return nextafter(in, dir); } EOC my $pos_inf = (99 ** 99) ** 99; my $neg_inf = -$pos_inf; my $next_down = nxtafter(1.9041105342991877e+258, $neg_inf); printf "%.16e\n", $next_down; my $next_up = nxtafter(-8.2727285363069939e-293, $pos_inf); printf "%.16e\n", $next_up; __END__ Outputs: 1.9041105342991875e+258 -8.2727285363069927e-293
With the latest MS compiler that I have (14.00.40310.41) I need to replace "nextafter" with "_nextafter" in order to get the script to compile.
But it then produces incorrect results anyway:
1.9041105342991884e+258 -7.9999999999999937e-293
Perhaps a more recent MS compiler fares better.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Determining the minimum representable increment/decrement possible?
by BrowserUk (Patriarch) on Jun 16, 2016 at 13:24 UTC

    I'm probably being thick here, but where does nextafter() come from?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.
      ... where does nextafter() come from?

      As pryrt noted, it's in math.h - which perl.h already (indirectly) includes.

      With my MS compiler, I found matches for the string "nextafter" in:
      C:\_64\Platform_SDK\Include\crt\float.h C:\_64\Platform_SDK\Include\crt\fpieee.h C:\_64\Platform_SDK\Include\crt\math.h C:\_64\Platform_SDK\src\crt\float.h C:\_64\Platform_SDK\src\crt\fpieee.h
      Cheers,
      Rob

      it looks like it's in math.h -- I didn't know about it until syphilis's post, either... I love how much I learn here. :-)

      For completeness, nextafter() is specified as part of math.h in C99 (section 7.12.11.3 in the N1256 draft).