diff --git a/c/pgtypes.c b/c/pgtypes.c index c51226b..cb4eb41 100644 --- a/c/pgtypes.c +++ b/c/pgtypes.c @@ -55,7 +55,7 @@ typedef struct { if (SvIOK(val)) iv = SvIV(val); \ else if (SvNOK(val)) { \ NV nv = SvNV(val); \ - if (nv < IV_MIN || nv > IV_MAX || fabs(nv - floor(nv)) > 0.0000000001) SERR("expected integer");\ + if (nv < IV_MIN || nv > IV_MAX || fabs((double)(nv - floor(nv))) > 0.0000000001) SERR("expected integer");\ iv = SvIV(val); \ } else if (SvPOK(val)) {\ STRLEN sl; \ @@ -503,7 +503,7 @@ SENDFN(uuid) { RECVFN(timestamp) { RLEN(8); IV ts = fu_frombeI(64, buf); - return newSVnv(((double)ts / 1000000) + UNIX_PG_EPOCH); + return newSVnv(((NV)ts / 1000000) + UNIX_PG_EPOCH); } SENDFN(timestamp) { diff --git a/t/json_format.t b/t/json_format.t index e7f41d5..0797a4f 100644 --- a/t/json_format.t +++ b/t/json_format.t @@ -5,6 +5,7 @@ use Test::More; use Tie::Array; use Tie::Hash; use FU::Util 'json_format'; +use Config; sub MyToJSON::TO_JSON { [scalar @_, ref $_[0], ${$_[0]}] } @@ -54,7 +55,7 @@ my @tests = ( ''.$$, '"'.$$.'"', do { my $x = 12; utf8::decode($x); $x }, '"12"', do { no warnings 'numeric'; my $x = '19a'; $x += 0; $x }, '19', - 1844674407370955161 / 10, '1.84467440737096e+17', + 1844674407370955161 / 10, $Config{uselongdouble} ? 184467440737095516 : '1.84467440737096e+17', ); my @errors = ( diff --git a/t/json_parse.t b/t/json_parse.t index d223077..901d01f 100644 --- a/t/json_parse.t +++ b/t/json_parse.t @@ -3,6 +3,7 @@ use Test::More; use FU::Util 'json_parse'; no warnings 'experimental::builtin'; use builtin 'is_bool', 'created_as_number'; +use Config; my @error = ( '', @@ -96,8 +97,8 @@ num ' -0 ', 0; num '-9223372036854775808'; num '9223372036854775807'; num '18446744073709551615'; -num '-9223372036854775809', -9.22337203685478e+18; -num '18446744073709551616', 1.84467440737096e+19; +num '-9223372036854775809', $Config{uselongdouble} ? -9.22337203685477581e+18 : -9.22337203685478e+18; +num '18446744073709551616', $Config{uselongdouble} ? 1.84467440737095516e+19 : 1.84467440737096e+19; num '1.234'; num '1e5', 100000; num '1e+5', 100000; diff --git a/t/pgtypes.t b/t/pgtypes.t index 326ccce..ba18815 100644 --- a/t/pgtypes.t +++ b/t/pgtypes.t @@ -2,6 +2,7 @@ use v5.36; use Test::More; no warnings 'experimental::builtin'; use builtin qw/true false is_bool created_as_number/; +use Config; plan skip_all => $@ if !eval { require FU::Pg; } && $@ =~ /Unable to load libpq/; die $@ if $@;