in reply to Re^2: XS, C doubles and -Duselongdouble
in thread XS, C doubles and -Duselongdouble

It's really difficult to get XS code right that does different things for different types of input; if I were you, I'd document that Math::GMPz->new takes a string of digits, and let the caller worry about anything beyond that.

Update: or provide a perl new_from_number that looks something like this:

use Config; sub new_from_number { my $class = shift; my $num = shift; my $fmt = '%.0f'; if (exists($Config{nv_preserves_uv_bits}) && $Config{nv_preserves_uv_bits} < 8 * $Config{uvsize} ) { $fmt = $num < 0 ? '%d' : '%u'; } $class->new(sprintf($fmt, $num)); }
I'm probably forgetting something important there, though.

Update 2: yes, I was forgetting to revert to %.0f for numbers outside [IV_MIN, UV_MAX].