in reply to XS and -Duse64bitint

You could add an explicit conversion to IV, e.g.

... char * str; sv_setiv(integer, SvIV(integer)); // <--- here str = SvPV_nolen(integer); ...

However, when doing that, I get (note the difference in the last two digits):

IV: 144115188075868217 IV: 144115188075868224

I suppose this is due to the insufficient precision in the NV representation...   Actually, I think it's too late to deal with this within your XS routine, as the value will already have been converted to NV when the SV gets passed to foo() - unless you use integer on the Perl side (but you already figured that out :)

Replies are listed 'Best First'.
Re^2: XS and -Duse64bitint
by syphilis (Archbishop) on Feb 13, 2007 at 23:00 UTC
    I suppose this is due to the insufficient precision in the NV representation

    Yes, you're right - the precision has been lost. I was fooled by the fact that the following tests re $x (the IV) and $y (the NV) return "true":
    $x == $y $x - 1 == $y - 1 $x + 1 == $y + 1
    I took that to indicate that perl knows that $y contains the value 144115188075868217, and that my problem was merely one of how to get at that value. The following tests also return "true":
    $x == $y + 1 $x == $y - 1
    which doesn't fit too well with the hypothesis that "no precision was lost" :-)

    Thanks almut, for setting me straight.

    Cheers,
    Rob