Use `__SIZEOF_DOUBLE__ == __SIZEOF_LONG_DOUBLE__` for the check, and guards to
make sure these new support files are only used for newlib.
http://reviews.llvm.org/D5419
Files:
include/cmath
include/support/newlib/math.h
src/support/newlib/math.cpp
Index: include/cmath
===================================================================
--- include/cmath
+++ include/cmath
@@ -305,6 +305,10 @@
#include "support/win32/math_win32.h"
#endif
+#if defined(_NEWLIB_VERSION)
+#include "support/newlib/math.h"
+#endif
+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
Index: include/support/newlib/math.h
===================================================================
--- include/support/newlib/math.h
+++ include/support/newlib/math.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_SUPPORT_NEWLIB_MATH_H
+#define _LIBCPP_SUPPORT_NEWLIB_MATH_H
+
+#if !defined(_NEWLIB_VERSION)
+#error This should only be used when Newlib is the underlying libc
+#endif
+
+#if __cplusplus
+extern "C" {
+#endif
+
+#if __SIZEOF_DOUBLE__ == __SIZEOF_LONG_DOUBLE__
+double nexttoward(double d, long double td);
+float nexttowardf(float f, long double td);
+long double nexttowardl(long double ld, long double td);
+
+long double logbl(long double x);
+#endif
+
+#if __cplusplus
+}
+#endif
+
+#endif
+
Index: src/support/newlib/math.cpp
===================================================================
--- src/support/newlib/math.cpp
+++ src/support/newlib/math.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <math.h>
+#include "support/newlib/math.h"
+
+#if defined(_NEWLIB_VERSION)
+
+#if __SIZEOF_DOUBLE__ == __SIZEOF_LONG_DOUBLE__
+// nexttoward* functions are precisely the same as their nextafter* siblings
+// when long double is the same as double.
+double nexttoward(double d, long double td) {
+ return nextafter(d, (double)td);
+}
+
+float nexttowardf(float f, long double td) {
+ return nextafterf(f, (float)td);
+}
+
+long double nexttowardl(long double ld, long double td) {
+ return nextafter((double)ld, (double)td);
+}
+
+long double logbl(long double x) {
+ return logb((double)x);
+}
+#endif
+
+#endif
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits