Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: convert bigint to int

by syphilis (Chancellor)
on Apr 05, 2017 at 14:38 UTC ( #1187132=note: print w/replies, xml ) Need Help??


in reply to convert bigint to int

This script creates a variable that's a Math::BigInt object, and then changes that variable into a normal integer value:
use warnings; use strict; use Math::BigInt; use Devel::Peek; my $x = Math::BigInt->new(42); Dump $x; # Shows that $x is a # Math::BigInt object print "\n ########\n ########\n\n"; $x = "$x" + 0; Dump $x; # Shows that $x is # a normal integer
That's my answer to the question that I'm guessing you want answered.

That script outputs:
SV = PV(0x2ee308) at 0x3481a0 REFCNT = 1 FLAGS = (ROK) RV = 0x2ed750 SV = PVHV(0x32d528) at 0x2ed750 REFCNT = 1 FLAGS = (OBJECT,SHAREKEYS) STASH = 0x350118 "Math::BigInt ARRAY = 0x334b38 (0:6, 1:2) hash quality = 125.0% KEYS = 2 FILL = 2 MAX = 7 Elt "sign" HASH = 0x46c14520 SV = PV(0x2ee298) at 0x33dd58 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x24f9288 "+"\0 CUR = 1 LEN = 10 COW_REFCNT = 1 Elt "value" HASH = 0xaea09fe1 SV = IV(0x33de38) at 0x33de48 REFCNT = 1 FLAGS = (ROK) RV = 0x33dda0 SV = PVAV(0x2ef240) at 0x33dda0 REFCNT = 1 FLAGS = () ARRAY = 0x2871cc8 FILL = 0 MAX = 0 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = IV(0x33dd78) at 0x33dd88 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 42 PV = 0x2ed750 "" CUR = 0 LEN = 0 ######## ######## SV = PVIV(0x346738) at 0x3481a0 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 42 PV = 0
Only caveat I can spot is that if $x had been created as my $x = 42; then the PV slot would not have been set at all (on perl-5.24.0, anyway).

Cheers,
Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1187132]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-05-28 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?