#! perl -slw use strict; use Config; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'ICexample', CLEAN_AFTER_BUILD =>0; static const unsigned __int64 i = 0x7ff0000000000001; SV*snan2() { // Allocate a new SvPV with some junk pv data SV *ret = newSVpvn( "JustJunk", 8 ); sv_setnv( ret, *(double*)&i ); // Now point the PV pointer directly at the NV memory so we can access it // (the NV) from perl without going through pack 'd'/'F' SvPV_set( ret, (char*)&( ( (XPVNV*)ret->sv_any )->xnv_u.xnv_nv ) ); // make it persist SvREFCNT_inc_void_NN( ret ); // Make sure noone can mess with it. SvREADONLY( ret ); return ret; } END_C ## Get an SNAN. my $snan2 = snan2(); ##Print its numeric value AND its bit pattern bypassing SVNV?() printf "%f\n%x\n", $snan2, unpack 'Q', $snan2; ## Same thing as the printf '%x', unpack 'Q' above ## that *might* work on 32-bit that doesn't have Q print scalar reverse unpack 'h*', $snan2; __END__ C:\test>snan-ic.pl Use of uninitialized value in printf at C:\test\snan-ic.pl line 32. 1.#SNAN0 0 4e414e53232e31 #### Notionally, a fully loaded SV looks vaguely like this: SV*->[ SVANY ]->[ IV ] [ FLAGS ] [ NV ] [ PV ]->"some text" What my code above does is this: SV*->[ SVANY ]->[ IV ] [ FLAGS ] [ NV ]<-+ [ PV ]--+ Point the PV at the memory holding the NV.