This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use the multiplication test instead of the DBL_MAX/LDBL_MAX.
authorJarkko Hietaniemi <jhi@iki.fi>
Fri, 12 Sep 2014 11:24:15 +0000 (07:24 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Fri, 12 Sep 2014 11:54:41 +0000 (07:54 -0400)
Comparing to decimal float constants feels unclean.

perl.h

diff --git a/perl.h b/perl.h
index 39bf241..55b33de 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -2023,8 +2023,11 @@ EXTERN_C long double modfl(long double, long double *);
 #       define Perl_isfinite(x) isfinite(x)
 #     elif defined(HAS_FINITE)
 #       define Perl_isfinite(x) finite(x)
-#     elif defined(DBL_MAX)
-#       define Perl_isfinite(x) ((x) <= DBL_MAX && (x) >= -DBL_MAX)
+#     else
+/* For the infinities the multiplication returns nan,
+ * for the nan the multiplication also returns nan,
+ * for everything else (that is, finite) zero should be returned. */
+#       define Perl_isfinite(x) ((x) * 0 == 0)
 #     endif
 #   endif
 #endif
@@ -2312,10 +2315,8 @@ int isnan(double d);
 #        define Perl_isfinitel(x) finitel(x)
 #    elif defined(HAS_INFL) && defined(HAS_NANL)
 #        define Perl_isfinitel(x) !(isinfl(x)||isnanl(x))
-#    elif defined(LDBL_MAX)
-#        define Perl_isfinitel(x) ((x) <= LDBL_MAX && (x) >= -LDBL_MAX)
 #    else
-#        define Perl_isfinitel(x) ((x) * 0 == 0)
+#        define Perl_isfinitel(x) ((x) * 0 == 0)  /* See Perl_isfinite. */
 #    endif
 #endif