From 012158cce809ef509560642dac421f021f952e2c Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Sat, 10 Jul 2021 21:03:05 +0900 Subject: [PATCH] libc/math: Add fmax and fmin functions Add fmax and fmin functions. - fmax, fmaxf, fmaxl - fmin, fminf, fminl --- libs/libc/math/Make.defs | 2 ++ libs/libc/math/lib_fmax.c | 39 ++++++++++++++++++++++++++++++++++++++ libs/libc/math/lib_fmaxf.c | 37 ++++++++++++++++++++++++++++++++++++ libs/libc/math/lib_fmaxl.c | 39 ++++++++++++++++++++++++++++++++++++++ libs/libc/math/lib_fmin.c | 39 ++++++++++++++++++++++++++++++++++++++ libs/libc/math/lib_fminf.c | 37 ++++++++++++++++++++++++++++++++++++ libs/libc/math/lib_fminl.c | 39 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 232 insertions(+) create mode 100644 libs/libc/math/lib_fmax.c create mode 100644 libs/libc/math/lib_fmaxf.c create mode 100644 libs/libc/math/lib_fmaxl.c create mode 100644 libs/libc/math/lib_fmin.c create mode 100644 libs/libc/math/lib_fminf.c create mode 100644 libs/libc/math/lib_fminl.c diff --git a/libs/libc/math/Make.defs b/libs/libc/math/Make.defs index d4e30c8a68..5ea034d959 100644 --- a/libs/libc/math/Make.defs +++ b/libs/libc/math/Make.defs @@ -52,6 +52,8 @@ CSRCS += lib_expm1.c lib_expm1f.c lib_expm1l.c CSRCS += lib_lround.c lib_lroundf.c lib_lroundl.c CSRCS += lib_llround.c lib_llroundf.c lib_llroundl.c CSRCS += lib_nan.c lib_nanf.c lib_nanl.c +CSRCS += lib_fmax.c lib_fmaxf.c lib_fmaxl.c +CSRCS += lib_fmin.c lib_fminf.c lib_fminl.c CSRCS += __cos.c __sin.c lib_gamma.c lib_lgamma.c diff --git a/libs/libc/math/lib_fmax.c b/libs/libc/math/lib_fmax.c new file mode 100644 index 0000000000..1cb62c06a6 --- /dev/null +++ b/libs/libc/math/lib_fmax.c @@ -0,0 +1,39 @@ +/**************************************************************************** + * libs/libc/math/lib_fmax.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double fmax(double x, double y) +{ + return ((x > y) ? x : y); +} +#endif diff --git a/libs/libc/math/lib_fmaxf.c b/libs/libc/math/lib_fmaxf.c new file mode 100644 index 0000000000..1e545aa26b --- /dev/null +++ b/libs/libc/math/lib_fmaxf.c @@ -0,0 +1,37 @@ +/**************************************************************************** + * libs/libc/math/lib_fmaxf.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +float fmaxf(float x, float y) +{ + return ((x > y) ? x : y); +} diff --git a/libs/libc/math/lib_fmaxl.c b/libs/libc/math/lib_fmaxl.c new file mode 100644 index 0000000000..ae7a27886e --- /dev/null +++ b/libs/libc/math/lib_fmaxl.c @@ -0,0 +1,39 @@ +/**************************************************************************** + * libs/libc/math/lib_fmaxl.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double fmaxl(long double x, long double y) +{ + return ((x > y) ? x : y); +} +#endif diff --git a/libs/libc/math/lib_fmin.c b/libs/libc/math/lib_fmin.c new file mode 100644 index 0000000000..c494575dbd --- /dev/null +++ b/libs/libc/math/lib_fmin.c @@ -0,0 +1,39 @@ +/**************************************************************************** + * libs/libc/math/lib_fmin.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double fmin(double x, double y) +{ + return ((x < y) ? x : y); +} +#endif diff --git a/libs/libc/math/lib_fminf.c b/libs/libc/math/lib_fminf.c new file mode 100644 index 0000000000..1ba6edf78e --- /dev/null +++ b/libs/libc/math/lib_fminf.c @@ -0,0 +1,37 @@ +/**************************************************************************** + * libs/libc/math/lib_fminf.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +float fminf(float x, float y) +{ + return ((x < y) ? x : y); +} diff --git a/libs/libc/math/lib_fminl.c b/libs/libc/math/lib_fminl.c new file mode 100644 index 0000000000..22e74cef84 --- /dev/null +++ b/libs/libc/math/lib_fminl.c @@ -0,0 +1,39 @@ +/**************************************************************************** + * libs/libc/math/lib_fminl.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double fminl(long double x, long double y) +{ + return ((x < y) ? x : y); +} +#endif