Skip to content

Remove unnecessary C99< checks for maths functions #4936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ _LT_AC_TRY_DLOPEN_SELF([
dnl Checks for library functions.
AC_CHECK_FUNCS(getpid kill finite sigsetjmp)

AC_CHECK_DECLS([isfinite, isnan, isinf], [], [], [[#include <math.h>]])

ZEND_CHECK_FLOAT_PRECISION

dnl Test whether double cast to long preserves least significant bits.
Expand Down Expand Up @@ -393,13 +391,7 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <math.h>
#include <stdlib.h>

#ifdef HAVE_ISNAN
#define zend_isnan(a) isnan(a)
#elif defined(HAVE_FPCLASS)
#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
#else
#define zend_isnan(a) 0
#endif

int main(int argc, char** argv)
{
Expand All @@ -422,16 +414,7 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <math.h>
#include <stdlib.h>

#ifdef HAVE_ISINF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to C99 the INFINITY macro should always exist, so it should be possibly to adjust the _zend_get_inf implementation to always use that and drop the two autoconf checks for infinity representations here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly for NAN. That one is not guaranteed to exist, but as PHP assumes it's running on a platform with IEEE 754 compliant floats, it should be defined on platforms we target.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I would suggest doing this separately, before handling zend_isinf and friends, as it removes some of the more ugly users...)

#define zend_isinf(a) isinf(a)
#elif defined(INFINITY)
/* Might not work, but is required by ISO C99 */
#define zend_isinf(a) (((a)==INFINITY)?1:0)
#elif defined(HAVE_FPCLASS)
#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
#else
#define zend_isinf(a) 0
#endif

int main(int argc, char** argv)
{
Expand All @@ -454,16 +437,7 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <math.h>
#include <stdlib.h>

#ifdef HAVE_ISINF
#define zend_isinf(a) isinf(a)
#elif defined(INFINITY)
/* Might not work, but is required by ISO C99 */
#define zend_isinf(a) (((a)==INFINITY)?1:0)
#elif defined(HAVE_FPCLASS)
#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
#else
#define zend_isinf(a) 0
#endif

int main(int argc, char** argv)
{
Expand All @@ -487,13 +461,7 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <math.h>
#include <stdlib.h>

#ifdef HAVE_ISNAN
#define zend_isnan(a) isnan(a)
#elif defined(HAVE_FPCLASS)
#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
#else
#define zend_isnan(a) 0
#endif

int main(int argc, char** argv)
{
Expand Down
24 changes: 0 additions & 24 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,11 @@ extern "C++" {
#include <math.h>

#ifndef zend_isnan
#if HAVE_DECL_ISNAN
#define zend_isnan(a) isnan(a)
#elif defined(HAVE_FPCLASS)
#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
#else
#define zend_isnan(a) ((a) != (a))
#endif
#endif

#if HAVE_DECL_ISINF
#define zend_isinf(a) isinf(a)
#elif defined(INFINITY)
/* Might not work, but is required by ISO C99 */
#define zend_isinf(a) (((a)==INFINITY || (a)==-INFINITY)?1:0)
#elif defined(HAVE_FPCLASS)
#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
#else
#define zend_isinf(a) 0
#endif

#if HAVE_DECL_ISFINITE
#define zend_finite(a) isfinite(a)
#elif defined(HAVE_FINITE)
#define zend_finite(a) finite(a)
#elif defined(fpclassify)
#define zend_finite(a) ((fpclassify((a))!=FP_INFINITE&&fpclassify((a))!=FP_NAN)?1:0)
#else
#define zend_finite(a) (zend_isnan(a) ? 0 : zend_isinf(a) ? 0 : 1)
#endif

#endif
#endif /* ifndef ZEND_ACCONFIG_H_NO_C_PROTOS */
Expand Down
8 changes: 0 additions & 8 deletions ext/standard/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,6 @@ if test "$ac_cv_attribute_aligned" = "yes"; then
AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [whether the compiler supports __attribute__ ((__aligned__))])
fi

dnl
dnl Check for available functions
dnl
dnl log2 could be used to improve the log function, however it requires C99. The
dnl check for log2 should be turned on, as soon as we support C99.
AC_CHECK_FUNCS(asinh acosh atanh log1p hypot)
AC_FUNC_FNMATCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the removal of AC_FUNC_FNMATCH here was not intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes indeed


dnl
dnl Check if there is a support means of creating a new process and defining
dnl which handles it receives
Expand Down
105 changes: 7 additions & 98 deletions ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,83 +204,6 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
}
/* }}} */

/* {{{ php_asinh
*/
static double php_asinh(double z)
{
#ifdef HAVE_ASINH
return(asinh(z));
#else
# ifdef _WIN64
if (z >= 0) {
return log(z + sqrt(z * z + 1));
}
else {
return -log(-z + sqrt(z * z + 1));
}
# else
return(log(z + sqrt(1 + pow(z, 2))) / log(M_E));
# endif
#endif
}
/* }}} */

/* {{{ php_acosh
*/
static double php_acosh(double x)
{
#ifdef HAVE_ACOSH
return(acosh(x));
#else
# ifdef _WIN64
if (x >= 1) {
return log(x + sqrt(x * x - 1));
} else {
return ZEND_NAN;
}
# else
return(log(x + sqrt(x * x - 1)));
# endif
#endif
}
/* }}} */

/* {{{ php_atanh
*/
static double php_atanh(double z)
{
#ifdef HAVE_ATANH
return(atanh(z));
#else
return(0.5 * log((1 + z) / (1 - z)));
#endif
}
/* }}} */

/* {{{ php_log1p
*/
static double php_log1p(double x)
{
#ifdef HAVE_LOG1P
return(log1p(x));
#else
return(log(1 + x));
#endif
}
/* }}} */

/* {{{ php_expm1
*/
static double php_expm1(double x)
{
#ifndef PHP_WIN32
return(expm1(x));
#else
return(exp(x) - 1);
#endif
}
/* }}}*/

/* {{{ proto int|float abs(int|float number)
Return the absolute value of the number */
PHP_FUNCTION(abs)
Expand Down Expand Up @@ -533,7 +456,7 @@ PHP_FUNCTION(asinh)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_DOUBLE(num)
ZEND_PARSE_PARAMETERS_END();
RETURN_DOUBLE(php_asinh(num));
RETURN_DOUBLE(asinh(num));
}
/* }}} */

Expand All @@ -546,7 +469,7 @@ PHP_FUNCTION(acosh)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_DOUBLE(num)
ZEND_PARSE_PARAMETERS_END();
RETURN_DOUBLE(php_acosh(num));
RETURN_DOUBLE(acosh(num));
}
/* }}} */

Expand All @@ -559,7 +482,7 @@ PHP_FUNCTION(atanh)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_DOUBLE(num)
ZEND_PARSE_PARAMETERS_END();
RETURN_DOUBLE(php_atanh(num));
RETURN_DOUBLE(atanh(num));
}
/* }}} */

Expand Down Expand Up @@ -644,10 +567,7 @@ PHP_FUNCTION(exp)
/* }}} */

/* {{{ proto float expm1(float number)
Returns exp(number) - 1, computed in a way that accurate even when the value of number is close to zero */
/*
WARNING: this function is experimental: it could change its name or
disappear in the next version of PHP!
Returns exp(number) - 1, computed in a way that accurate even when the value of number is close to zero
*/
PHP_FUNCTION(expm1)
{
Expand All @@ -657,15 +577,12 @@ PHP_FUNCTION(expm1)
Z_PARAM_DOUBLE(num)
ZEND_PARSE_PARAMETERS_END();

RETURN_DOUBLE(php_expm1(num));
RETURN_DOUBLE(expm1(num));
}
/* }}} */

/* {{{ proto float log1p(float number)
Returns log(1 + number), computed in a way that accurate even when the value of number is close to zero */
/*
WARNING: this function is experimental: it could change its name or
disappear in the next version of PHP!
Returns log(1 + number), computed in a way that accurate even when the value of number is close to zero
*/
PHP_FUNCTION(log1p)
{
Expand All @@ -675,7 +592,7 @@ PHP_FUNCTION(log1p)
Z_PARAM_DOUBLE(num)
ZEND_PARSE_PARAMETERS_END();

RETURN_DOUBLE(php_log1p(num));
RETURN_DOUBLE(log1p(num));
}
/* }}} */

Expand All @@ -695,11 +612,9 @@ PHP_FUNCTION(log)
RETURN_DOUBLE(log(num));
}

#ifdef HAVE_LOG2
if (base == 2.0) {
RETURN_DOUBLE(log2(num));
}
#endif

if (base == 10.0) {
RETURN_DOUBLE(log10(num));
Expand Down Expand Up @@ -757,13 +672,7 @@ PHP_FUNCTION(hypot)
Z_PARAM_DOUBLE(num2)
ZEND_PARSE_PARAMETERS_END();

#if HAVE_HYPOT
RETURN_DOUBLE(hypot(num1, num2));
#elif defined(_MSC_VER)
RETURN_DOUBLE(_hypot(num1, num2));
#else
RETURN_DOUBLE(sqrt((num1 * num1) + (num2 * num2)));
#endif
}
/* }}} */

Expand Down
13 changes: 0 additions & 13 deletions win32/build/confutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2300,19 +2300,6 @@ function generate_config_h()
outfile.WriteLine("#define " + keys[i] + " " + pieces);
}

if (VS_TOOLSET) {
if (VCVERS >= 1800) {
outfile.WriteLine("");
outfile.WriteLine("#define HAVE_ACOSH 1");
outfile.WriteLine("#define HAVE_ASINH 1");
outfile.WriteLine("#define HAVE_ATANH 1");
}
if (VCVERS >= 1900) {
outfile.WriteLine("#define HAVE_LOG1P 1");
}
}


outfile.Close();
}

Expand Down