Skip to content

Commit b1f4488

Browse files
committed
math.h: match other OSes more closely.
isnan() and isinf() are type-generic macros, not usually declared as functions. Remove the function declarations and the big comment talking about how we shouldn't expose them. isnanl() and isinfl() are exposed as functions by glibc (but not the BSDs), and we've always had the definitions, so we can increase source compatibility there trivially. See the discussion on llvm/llvm-project#96008 for more background. Change-Id: I798153f710794870bb4864f2ae8b98147f9d8763
1 parent 883e08b commit b1f4488

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

libc/include/math.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,6 @@ long double fmal(long double __x, long double __y, long double __z);
308308
#define islessgreater(x, y) __builtin_islessgreater((x), (y))
309309
#define isunordered(x, y) __builtin_isunordered((x), (y))
310310

311-
/*
312-
* https://code.google.com/p/android/issues/detail?id=271629
313-
* To be fully compliant with C++, we need to not define these (C doesn't
314-
* specify them either). Exposing these means that isinf and isnan will have a
315-
* return type of int in C++ rather than bool like they're supposed to be.
316-
*
317-
* GNU libstdc++ 4.9 isn't able to handle a standard compliant C library. Its
318-
* <cmath> will `#undef isnan` from math.h and only adds the function overloads
319-
* to the std namespace, making it impossible to use both <cmath> (which gets
320-
* included by a lot of other standard headers) and ::isnan.
321-
*/
322-
int (isinf)(double __x) __attribute_const__;
323-
int (isnan)(double __x) __attribute_const__;
324-
325311
/* POSIX extensions. */
326312

327313
extern int signgam;
@@ -362,6 +348,7 @@ double gamma(double __x);
362348
double scalb(double __x, double __exponent);
363349
double drem(double __x, double __y);
364350
int finite(double __x) __attribute_const__;
351+
int isinff(float __x) __attribute_const__;
365352
int isnanf(float __x) __attribute_const__;
366353
double gamma_r(double __x, int* _Nonnull __sign);
367354
double lgamma_r(double __x, int* _Nonnull __sign);
@@ -402,6 +389,8 @@ void sincosl(long double __x, long double* _Nonnull __sin, long double* _Nonnull
402389
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
403390
#define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
404391
#define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
392+
int isinfl(long double __x) __attribute_const__;
393+
int isnanl(long double __x) __attribute_const__;
405394
#endif
406395

407396
__END_DECLS

tests/math_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,7 @@ TEST(math_h, isnan_function) {
367367
// Historical BSD cruft that isn't exposed in <math.h> any more.
368368
extern "C" int __isnan(double);
369369
extern "C" int __isnanf(float);
370-
extern "C" int isnanf(float);
371370
extern "C" int __isnanl(long double);
372-
extern "C" int isnanl(long double);
373371

374372
TEST(math_h, __isnan) {
375373
#if defined(ANDROID_HOST_MUSL)

0 commit comments

Comments
 (0)