From e7619633bdbe2648f88721c739bcd8d1a824e1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 19 Apr 2018 17:35:57 +0200 Subject: [PATCH] [liba] Add fmax in math.h header --- liba/Makefile | 2 ++ liba/include/math.h | 2 ++ liba/src/external/openbsd/s_fmax.c | 55 +++++++++++++++++++++++++++++ liba/src/external/openbsd/s_fmaxf.c | 47 ++++++++++++++++++++++++ libaxx/include/cmath | 4 +++ 5 files changed, 110 insertions(+) create mode 100644 liba/src/external/openbsd/s_fmax.c create mode 100644 liba/src/external/openbsd/s_fmaxf.c diff --git a/liba/Makefile b/liba/Makefile index 032f89ec2..9dc39e4de 100644 --- a/liba/Makefile +++ b/liba/Makefile @@ -60,6 +60,7 @@ objs += $(addprefix liba/src/external/openbsd/, \ s_erf.o \ s_expm1f.o\ s_fabsf.o \ + s_fmaxf.o \ s_floorf.o \ s_frexpf.o \ s_frexp.o \ @@ -107,6 +108,7 @@ objs += $(addprefix liba/src/external/openbsd/, \ s_cos.o \ s_expm1.o \ s_fabs.o \ + s_fmax.o \ s_floor.o \ s_log1p.o \ s_round.o \ diff --git a/liba/include/math.h b/liba/include/math.h index e9a26fbb5..7fef24005 100644 --- a/liba/include/math.h +++ b/liba/include/math.h @@ -57,6 +57,7 @@ float coshf(float x); float expf(float x); float expm1f(float x); float fabsf(float x); +float fmaxf(float x, float y); float floorf(float x); float fmodf(float x, float y); float frexpf(float x, int *eptr); @@ -95,6 +96,7 @@ double erfc(double x); double exp(double x); double expm1(double x); double fabs(double x); +double fmax(double x, double y); double floor(double x); double fmod(double x, double y); double frexp(double x, int *eptr); diff --git a/liba/src/external/openbsd/s_fmax.c b/liba/src/external/openbsd/s_fmax.c new file mode 100644 index 000000000..731f02095 --- /dev/null +++ b/liba/src/external/openbsd/s_fmax.c @@ -0,0 +1,55 @@ +/* $OpenBSD: s_fmax.c,v 1.4 2008/12/10 01:08:24 martynas Exp $ */ +/*- + * Copyright (c) 2004 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +double +fmax(double x, double y) +{ + /* Check for NaNs to avoid raising spurious exceptions. */ + if (isnan(x)) + return (y); + if (isnan(y)) + return (x); + + /* Handle comparisons of signed zeroes. */ + if (signbit(x) != signbit(y)) + if (signbit(x)) + return (y); + else + return (x); + + return (x > y ? x : y); +} + +#if LDBL_MANT_DIG == 53 +#ifdef __weak_alias +__weak_alias(fmaxl, fmax); +#endif /* __weak_alias */ +#endif /* LDBL_MANT_DIG == 53 */ diff --git a/liba/src/external/openbsd/s_fmaxf.c b/liba/src/external/openbsd/s_fmaxf.c new file mode 100644 index 000000000..7cd2c39ed --- /dev/null +++ b/liba/src/external/openbsd/s_fmaxf.c @@ -0,0 +1,47 @@ +/* $OpenBSD: s_fmaxf.c,v 1.2 2008/09/11 19:18:12 martynas Exp $ */ +/*- + * Copyright (c) 2004 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +float +fmaxf(float x, float y) +{ + /* Check for NaNs to avoid raising spurious exceptions. */ + if (isnan(x)) + return (y); + if (isnan(y)) + return (x); + + /* Handle comparisons of signed zeroes. */ + if (signbit(x) != signbit(y)) + if (signbit(x)) + return (y); + else + return (x); + + return (x > y ? x : y); +} diff --git a/libaxx/include/cmath b/libaxx/include/cmath index d0cd7e484..01822ec1e 100644 --- a/libaxx/include/cmath +++ b/libaxx/include/cmath @@ -23,6 +23,7 @@ #undef expf #undef expm1f #undef fabsf +#undef fmaxf #undef floorf #undef fmodf #undef hypotf @@ -57,6 +58,7 @@ #undef exp #undef expm1 #undef fabs +#undef fmax #undef floor #undef hypot #undef lgamma @@ -102,6 +104,8 @@ static inline double exp(double x) { return __builtin_exp(x); } static inline float exp(float x) { return __builtin_expf(x); } static inline double fabs(double x) { return __builtin_fabs(x); } static inline float fabs(float x) { return __builtin_fabsf(x); } +static inline double fmax(double x, double y) { return __builtin_fmax(x, y); } +static inline float fmax(float x, float y) { return __builtin_fmaxf(x, y); } static inline double floor(double x) { return __builtin_floor(x); } static inline float floor(float x) { return __builtin_floorf(x); } static inline int fpclassify(double x) { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x); }