Re: Perl's newSViv() versus 64-bit ints? - Mailing list pgsql-hackers

From Salvador Fandiño
Subject Re: Perl's newSViv() versus 64-bit ints?
Date
Msg-id 56E3C3B6.7010607@gmail.com
Whole thread Raw
In response to Perl's newSViv() versus 64-bit ints?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Perl's newSViv() versus 64-bit ints?
List pgsql-hackers
On 03/12/2016 12:49 AM, Tom Lane wrote:
> Anybody know what will happen when passing a uint64 to newSViv()?

On 64 bit platforms, it is just interpreted as a signed integer, any 
number with the upper bit set will become negative. Perl provides 
newSVuv for unsigned numbers.

On 32bit platforms and Perls compiled with 32 bit IVs the number is 
truncated. My module Math::Int64 can be used to add support for 64bit 
numbers there. It has a C API[*] which allows calling it from C code 
easily. Another possibility is to just use newSVnv(), but NVs are not 
able to represent all the uint64 range precisely (IIRC, they can 
represent integers up to 48bits?).

Well, and then you can always use some bigint module, but AFAIK, the 
ones distributed in the Perl core do not provide a C API.


* https://metacpan.org/pod/Math::Int64#C-API



pgsql-hackers by date:

Previous
From: Alexander Kuleshov
Date:
Subject: [PATCH] Use MemoryContextAlloc() in the MemoryContextAllocZero() and MemoryContextAllocZeroAligned()
Next
From: Amit Kapila
Date:
Subject: Re: [COMMITTERS] pgsql: Provide much better wait information in pg_stat_activity.