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,30 @@ +//===----------------------------------------------------------------------===// +// +// 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 __cplusplus +extern "C" { +#endif + +#if defined(__arm__) && !defined(__LP64__) +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,36 @@ +//===----------------------------------------------------------------------===// +// +// 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 "support/newlib/math.h" + +#include + +#if defined(__arm__) && !defined(__LP64__) +static_assert(sizeof(long double) == sizeof(double), + "These implementations assume: LDBL == DBL"); +// On 32bit arm, since (long double) == (double), nexttoward* functions are +// the same as their nextafter* siblings. + +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 +