You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2026/10/22 10:41:09 UTC

(nuttx) 08/08: libs/libm: Add lgammaf(), lgammal(), tgammaf() and tgammal().

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit d64d5ae64a785c92a52287a1a99f00098534c098
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Mon Oct 19 02:30:28 2026 +0200

    libs/libm: Add lgammaf(), lgammal(), tgammaf() and tgammal().
    
    math.h declares these functions, but the built-in libm had only
    lgamma() and tgamma().  Call the double versions, as expl() and logl()
    also have the range of double.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 libs/libm/libm/CMakeLists.txt |  4 ++++
 libs/libm/libm/Make.defs      |  1 +
 libs/libm/libm/lib_lgammaf.c  | 41 +++++++++++++++++++++++++++++++++++++++
 libs/libm/libm/lib_lgammal.c  | 45 +++++++++++++++++++++++++++++++++++++++++++
 libs/libm/libm/lib_tgammaf.c  | 41 +++++++++++++++++++++++++++++++++++++++
 libs/libm/libm/lib_tgammal.c  | 45 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 177 insertions(+)

diff --git a/libs/libm/libm/CMakeLists.txt b/libs/libm/libm/CMakeLists.txt
index 7ec03aca011..f7a4e617576 100644
--- a/libs/libm/libm/CMakeLists.txt
+++ b/libs/libm/libm/CMakeLists.txt
@@ -151,6 +151,10 @@ if(CONFIG_LIBM)
       __sin.c
       lib_gamma.c
       lib_lgamma.c
+      lib_lgammaf.c
+      lib_lgammal.c
+      lib_tgammaf.c
+      lib_tgammal.c
       lib_exp2.c
       lib_exp2f.c
       lib_exp2l.c
diff --git a/libs/libm/libm/Make.defs b/libs/libm/libm/Make.defs
index 312abcd9cc6..44fc07f10fe 100644
--- a/libs/libm/libm/Make.defs
+++ b/libs/libm/libm/Make.defs
@@ -57,6 +57,7 @@ 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
+CSRCS += lib_lgammaf.c lib_lgammal.c lib_tgammaf.c lib_tgammal.c
 CSRCS += lib_exp2.c lib_exp2f.c lib_exp2l.c
 CSRCS += lib_log1p.c lib_log1pf.c lib_log1pl.c
 CSRCS += lib_cbrtf.c lib_cbrtl.c
diff --git a/libs/libm/libm/lib_lgammaf.c b/libs/libm/libm/lib_lgammaf.c
new file mode 100644
index 00000000000..6f48b1ffae1
--- /dev/null
+++ b/libs/libm/libm/lib_lgammaf.c
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libm/libm/lib_lgammaf.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+float lgammaf(float x)
+{
+  return (float)lgamma(x);
+}
+#endif
diff --git a/libs/libm/libm/lib_lgammal.c b/libs/libm/libm/lib_lgammal.c
new file mode 100644
index 00000000000..175cae80076
--- /dev/null
+++ b/libs/libm/libm/lib_lgammal.c
@@ -0,0 +1,45 @@
+/****************************************************************************
+ * libs/libm/libm/lib_lgammal.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double lgammal(long double x)
+{
+  /* Like expl() and logl(), this has the precision and the range of
+   * double.
+   */
+
+  return lgamma((double)x);
+}
+#endif
diff --git a/libs/libm/libm/lib_tgammaf.c b/libs/libm/libm/lib_tgammaf.c
new file mode 100644
index 00000000000..ba66b19df52
--- /dev/null
+++ b/libs/libm/libm/lib_tgammaf.c
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * libs/libm/libm/lib_tgammaf.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+float tgammaf(float x)
+{
+  return (float)tgamma(x);
+}
+#endif
diff --git a/libs/libm/libm/lib_tgammal.c b/libs/libm/libm/lib_tgammal.c
new file mode 100644
index 00000000000..7053a26c3ce
--- /dev/null
+++ b/libs/libm/libm/lib_tgammal.c
@@ -0,0 +1,45 @@
+/****************************************************************************
+ * libs/libm/libm/lib_tgammal.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double tgammal(long double x)
+{
+  /* Like expl() and logl(), this has the precision and the range of
+   * double.
+   */
+
+  return tgamma((double)x);
+}
+#endif