On Tue, Nov 16, 2004 at 07:52:09AM +0100, Tassilo von Parseval wrote: > Hi, > > right now I'm lost a bit in the muddle of the various perl compilation > flags and the sizes of some C datatypes. The task is simply to get the > numerical maximum of a list of values. Could someone have a look at the > following XSUB, especially at the #defines at the beginning? In > particular, I am not sure about using long doubles when 64bit integers > are in effect:
On some platforms, sizeof(long double) is 8, so they can't accurately hold all the values that a 64 bit integer holds. So if you really want to be completely portable you're going to need something more complex than this which deals differently with IVs and NVs if the SV is an IV with a large value. This will get more complex still if you need it to work pre 5.8, because in 5.6 and earlier the IvOK flag is set if the IV slot is valid as an integer, rather than if it's numerically identical to the NV, because NV maths takes priority. eg: $ ~/Reference/5.6.2/bin/perl5.6.2-32 -MDevel::Peek -e '$a = 3.2; $a & 1; Dump $a' SV = PVNV(0x8010a0) at 0x806e6c REFCNT = 1 FLAGS = (IOK,NOK,pIOK,pNOK,IsUV) UV = 3 NV = 3.2 PV = 0 Nicholas Clark