Re: Odd output with 5.16.0, x86-64int architecture

[email protected] ("Sisyphus") Fri, 7 Sep 2012 11:27:27 +1000
Newsgroups perl.win32.vanilla
Message-ID <1E12483DC95946D69FEEC6C2796EB49F@desktop2>
----- Original Message ----- 
From: "Sisyphus" <[email protected]>
To: <[email protected]>
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