in reply to How can I test for the representation of an integer?

If I want to know whether a value is an integer value (IV) or not (as often happens), I just use the the XS function SvIOK().
If it returns true then it's an IV, otherwise it's something else.
#!perl -l use strict; use warnings; use Math::BigInt; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; int is_IV(SV * x) { if(SvIOK(x)) return 1; return 0; } EOC my $x = '42'; print is_IV($x); # 0 $x += 0; print is_IV($x); # 1 print is_IV(~0); # 1 (also UV) print is_IV('?'); # 0; my $mbi = Math::BigInt->new(1); print is_IV($mbi); # 0; print is_IV(2 ** 20); # 0 (NV)
Cheers,
Rob

Replies are listed 'Best First'.
Re^2: How can I test for the representation of an integer?
by sm@sh (Acolyte) on Apr 25, 2016 at 14:24 UTC
    Thanks - that answers my question perfectly.