----- Original Message ----- From: "Sisyphus" <sisyph...@optusnet.com.au>
To: <win32-vanilla@perl.org>
Sent: Friday, September 07, 2012 1:00 AM
Subject: Odd output with 5.16.0, x86-64int architecture


Hi,

Here's the demo (Inline::C) script:

###################################
use warnings;
use Config;
use Math::MPFR qw(:mpfr);

use Inline C => Config =>
   CCFLAGS => "-D__USE_MINGW_ANSI_STDIO=1 " . $Config{ccflags},
   BUILD_NOISY => 1;

use Inline C => <<'EOC';

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void check(char * in, SV * digits) {
    dXSARGS;
    long double ld;
    char *ptr, *buffer;;

    ld = strtold(in, &ptr);

    buffer = malloc(32 * sizeof(char));
    sprintf(buffer, "%.*Le", SvUV(digits) - 1, ld);
    ST(0) = sv_2mortal(newSVpv(buffer, 0));
    free(buffer);
    XSRETURN(1);

}

EOC

print check('1e-37', 18), "\n";
###################################

For both the x86 and x64 builds of Strawberry Perl-5.16.0 that script correctly outputs:
1.00000000000000000e-037

But for the x86-64int build of Strawberry Perl-5.16.0 I'm getting:
-0.00000000000000000e+000

Duh - it's just that I need to cast SvUV(digits) to an unsigned long:

sprintf(buffer, "%.*Le", (unsigned long)SvUV(digits) - 1, ld);

Cheers,
Rob

Reply via email to