This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
modfl emulation via truncl (C99) and copysignl.
authorJarkko Hietaniemi <jhi@iki.fi>
Sun, 7 Sep 2014 02:01:01 +0000 (22:01 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 8 Sep 2014 02:08:33 +0000 (22:08 -0400)
(We've had emulation for broken modfl before,
 but it used aintl, which is not that common.)

numeric.c
perl.h

index b4ea8b2..1716efb 100644 (file)
--- a/numeric.c
+++ b/numeric.c
@@ -1347,13 +1347,23 @@ Perl_isinfnan(NV nv)
     return FALSE;
 }
 
-#if ! defined(HAS_MODFL) && defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
+#ifndef HAS_MODFL
+/* C99 has truncl, pre-C99 Solaris had aintl */
+#  if defined(HAS_TRUNCL) && defined(HAS_COPYSIGNL)
+long double
+Perl_my_modfl(long double x, long double *ip)
+{
+       *ip = truncl(x);
+       return (x == *ip ? copysignl(0.0L, x) : x - *ip);
+}
+#  elif defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
 long double
 Perl_my_modfl(long double x, long double *ip)
 {
        *ip = aintl(x);
        return (x == *ip ? copysignl(0.0L, x) : x - *ip);
 }
+#  endif
 #endif
 
 #if ! defined(HAS_FREXPL) && defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
diff --git a/perl.h b/perl.h
index f3ae3eb..f94c617 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -1912,11 +1912,9 @@ typedef NVTYPE NV;
 #       ifndef HAS_MODFL_PROTO
 EXTERN_C long double modfl(long double, long double *);
 #      endif
-#   else
-#       if defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
+#   elif (defined(HAS_TRUNCL) || defined(HAS_AINTL)) && defined(HAS_COPYSIGNL)
         extern long double Perl_my_modfl(long double x, long double *ip);
 #           define Perl_modf(x,y) Perl_my_modfl(x,y)
-#       endif
 #   endif
 #   ifdef HAS_FREXPL
 #       define Perl_frexp(x,y) frexpl(x,y)