Skip to content

Instantly share code, notes, and snippets.

@run4flat
Last active December 31, 2015 13:49
Show Gist options
  • Save run4flat/7995003 to your computer and use it in GitHub Desktop.
Save run4flat/7995003 to your computer and use it in GitHub Desktop.
Most recent round of nvcc's interactions with SvNV and friends
SV = NV(0x89ed504) at 0x89d2308
REFCNT = 1
FLAGS = (NOK,READONLY,pNOK)
NV = 5
---------------------
The string interpretation of the floating point is 0.000000
-> when cast to a float, we have 0.000000; to a double, 0.000000
-> when directly printed as %f: 0.000000
-> real_constant is 5.000000
---------------------
SV = PVNV(0x8a50fc0) at 0x89d2308
REFCNT = 1
FLAGS = (NOK,POK,READONLY,pNOK,pPOK)
IV = 0
NV = 5
PV = 0x89dcdf0 "5"\0
CUR = 1
LEN = 36
---------------------
SV = NV(0x89ed50c) at 0x89d2298
REFCNT = 1
FLAGS = (NOK,READONLY,pNOK)
NV = 0.25
---------------------
The string interpretation of the floating point is 0.000000
-> when cast to a float, we have 0.000000; to a double, 0.000000
-> when directly printed as %f: 0.000000
-> real_constant is 0.250000
---------------------
SV = PVNV(0x8a50fd4) at 0x89d2298
REFCNT = 1
FLAGS = (NOK,POK,READONLY,pNOK,pPOK)
IV = 0
NV = 0.25
PV = 0x89d7b40 "0.25"\0
CUR = 4
LEN = 36
---------------------
SV = NV(0x89ed51c) at 0x89d21b8
REFCNT = 1
FLAGS = (NOK,READONLY,pNOK)
NV = -0.14
---------------------
The string interpretation of the floating point is 0.000000
-> when cast to a float, we have 0.000000; to a double, 0.000000
-> when directly printed as %f: 0.000000
-> real_constant is -0.140000
---------------------
SV = PVNV(0x8a50fe8) at 0x89d21b8
REFCNT = 1
FLAGS = (NOK,POK,READONLY,pNOK,pPOK)
IV = 0
NV = -0.14
PV = 0x89dbed0 "-0.14"\0
CUR = 5
LEN = 36
---------------------
use strict;
use warnings;
use ToTest;
ToTest::check_float_stuff(5.0);
ToTest::check_float_stuff(0.25);
ToTest::check_float_stuff(-0.14);
package ToTest;
use 5.008_008;
use strict;
use warnings;
our $VERSION = '0.04';
require XSLoader;
XSLoader::load('ToTest', $VERSION);
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/*#include "ppport.h"*/
MODULE = ToTest PACKAGE = ToTest
void
check_float_stuff(SV * constant_SV)
PROTOTYPE: $
PREINIT:
float real_const, constant;
double constant_d;
CODE:
sv_dump(constant_SV);
real_const = atof(SvPV_nolen(constant_SV));
printf("---------------------\n");
printf("The string interpretation of the floating point is %f\n", SvNVX(constant_SV));
// printf("The string interpretation of the floating point is %f\n", SvNV_nomg(constant_SV));
//printf("The string interpretation of constant_SV is %s; the floating point is %f\n",
// SvPV_nolen(constant_SV), SvNV_nomg(constant_SV));
constant = (float) SvNV_nomg(constant_SV);
constant_d = SvNV_nomg(constant_SV);
printf(" -> when cast to a float, we have %f; to a double, %f\n", constant, constant_d);
printf(" -> when directly printed as %%f: %f\n", SvNV(constant_SV));
printf(" -> real_constant is %f\n", real_const);
printf("---------------------\n");
sv_dump(constant_SV);
printf("---------------------\n\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment