in reply to Re: XS, C doubles and -Duselongdouble
in thread XS, C doubles and -Duselongdouble
What should happen there ? Should it croak with the message "Hey ... the GMP library doesn't handle ints bigger than 32-bit!!" ? Should it silently assign the value as a 32-bit int ? I've chosen to have the new() XS function read $num as a string using SvPV_nolen(), and then have the GMP library's mpz_set_str() function assign from that string - and that seems to assign the correct 64-bit value.use warnings; use Math::GMPz qw(:mpz); $num = 144115188075868217;# this is an IV $obj = Math::GMPz->new($num);
If, under a long double build of perl, the XS function now reads $num using SvPV_nolen(), and the value gets assigned using mpz_set_str(), then it gets the value wrong. There is no simple way (that I can see) for $obj to be assigned the value represented by $num - using the existing assignment operations provided by the GMP library. Of course, if $num fits into a C double anyway, then there's no problem. So ... I started to think along the lines that, since the GMP library did not support long doubles, it was unreasonable to expect that Math::GMPz should support long doubles (even though the build of perl did support them) - and that a croak/warning should be emitted iff precision was being lost.use warnings; use Math::GMPz qw(:mpz); $num = 2 ** 57 + 12345;# this is an NV $obj = Math::GMPz->new($num);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: XS, C doubles and -Duselongdouble
by ysth (Canon) on Jun 11, 2007 at 07:40 UTC |