Delivered-To: mlmmj-tyndur-devel
Received: from sv1.famkaufmann.info [176.9.73.67]
	by a9b8c5461646 with IMAP (fetchmail-6.3.26)
	for <mlmmj@localhost> (single-drop); Mon, 12 Apr 2021 21:18:14 +0000 (GMT)
Received: from localhost ([172.29.0.7])
	by sv1.famkaufmann.info with LMTP
	id 2BnxJgy5dGDOMgAALHnFKQ
	(envelope-from <hanna.reitz@mailbox.org>)
	for <mlmmj-tyndur-devel>; Mon, 12 Apr 2021 21:18:04 +0000
Delivered-To: tyndur-devel@tyndur.org
Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172])
	by sv1.famkaufmann.info (OpenSMTPD) with ESMTPS id 94e0506c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO)
	for <tyndur-devel@tyndur.org>;
	Mon, 12 Apr 2021 21:18:04 +0000 (UTC)
Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4FK1mW5t5gzQjn8
	for <tyndur-devel@tyndur.org>; Mon, 12 Apr 2021 23:18:03 +0200 (CEST)
Authentication-Results: spamfilter03.heinlein-hosting.de (amavisd-new);
	dkim=pass (2048-bit key) reason="pass (just generated, assumed good)"
	header.d=mailbox.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812;
	t=1618262283;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=tSTrMzwHMOy4XxVI7VLQqI8ChRhPchmRz6pgyGNjWQ8=;
	b=nB0XXLL53t8j4Rd30WleCtvRt8+GGHHm++Nx46Z/4MMe3Nca8QPw+/2OKPcrbBlUDOEVzo
	xX/zlm7ResE3xVU/S/rA/+u18bbBNzXAvxM7bt1OKk2xKcGCKXp/2Q2/+iyzIBw3Md8A47
	w4kGNjvP+aK+GXVCyPJ51erDFJGVcl/WHNEjIpReZk7RXr4hnlqwmCc+Ij3en368mvPptI
	OJYHmkYfe8OtsGzi5S/R7up8mZdmZxEV87N1NgxXAMqUgXuE9f6KGBVMIZ7d9MR+xl5Wbt
	Iz3AqWwliLWP2sbwv/I11Ri9CW6w9WmQ2Huzd0LSdhPDuv4WY7LmwJfnlk6iPw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mailbox.org; h=
	content-transfer-encoding:content-type:content-type:mime-version
	:references:in-reply-to:message-id:date:date:subject:subject
	:from:from:received; s=mail20150812; t=1618262279; bh=37NOGZdOJM
	uyorDC1ok74/FxSgjzkllVnPkpKS96flY=; b=lLr+5T3P36fDpX/8ASzlAbVLNp
	fXrotjiazdqdb9DCru9YBrXdCD+uZNU/ZesA7OJ3aY9IA/fylsgGJXd+8ZxJ3BIB
	n7hkcJNvBkVbse+7aCRQT/UWQDSm+qJ8AZ1ZsavLjJTRiiH/rI797Pcs+aEdd06O
	mJ+EnxkjwzLSzSvnTwARRtuaR/LYGKP37VgU1yW1pRE9cgcS4uKxFfp6TXDUvqly
	H86KLn+HoqBwY9vGcagNiZSUyKBATgPc6L1O3Pa3Q0C1VBzimf+aEWgDVktKytCc
	f6no6CIlytbscMdNUwXzbESRR/2ednIdk08BAhLVCHRp7M52edO/wpfjE6uA==
X-Virus-Scanned: amavisd-new at heinlein-support.de
Received: from smtp2.mailbox.org ([80.241.60.241])
	by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030)
	with ESMTP id 29bCZQ2hx8PS; Mon, 12 Apr 2021 23:17:59 +0200 (CEST)
From: Hanna Reitz <hanna.reitz@mailbox.org>
To: tyndur-devel@tyndur.org
Cc: Hanna Reitz <hanna.reitz@mailbox.org>
Subject: [PATCH 2/2] libm: pow{f,l}(), cbrt{,f,l}() und hypot{,f,l}()
Date: Mon, 12 Apr 2021 23:17:50 +0200
Message-Id: <20210412211750.716318-3-hanna.reitz@mailbox.org>
In-Reply-To: <20210412211750.716318-1-hanna.reitz@mailbox.org>
References: <20210412211750.716318-1-hanna.reitz@mailbox.org>
Errors-To: toni@tyndur.org
Precedence: list
Reply-To: tyndur-Patches <tyndur-devel@tyndur.org>
List-Id: tyndur-Patches <tyndur-devel.tyndur.org>
List-Unsubscribe: <mailto:tyndur-devel+unsubscribe@tyndur.org>
List-Post: <mailto:tyndur-devel@tyndur.org>
List-Help: <mailto:tyndur-devel+help@tyndur.org>
List-Subscribe: <mailto:tyndur-devel+subscribe@tyndur.org>
List-Owner: <mailto:toni@tyndur.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-MBO-SPAM-Probability: 
X-Rspamd-Score: -9.15 / 15.00 / 15.00
X-Rspamd-Queue-Id: 98B1917E8
X-Rspamd-UID: d372e0

+ float- und long-double-Versionen von pow(), alle Versionen von cbrt(),
  und alle Versionen von hypot().  Alles von µxoµcota kopiert, mit
  geänderter Lizenz (von MIT auf BSD-2).

Signed-off-by: Hanna Reitz <hanna.reitz@mailbox.org>
---
 src/modules/include/math.h           | 10 +++++++
 src/modules/lib/stdlibc/math/cbrt.c  | 44 ++++++++++++++++++++++++++++
 src/modules/lib/stdlibc/math/hypot.c | 44 ++++++++++++++++++++++++++++
 src/modules/lib/stdlibc/math/pow.c   | 31 +++++++++++++++++++-
 4 files changed, 128 insertions(+), 1 deletion(-)
 create mode 100644 src/modules/lib/stdlibc/math/cbrt.c
 create mode 100644 src/modules/lib/stdlibc/math/hypot.c

diff --git a/src/modules/include/math.h b/src/modules/include/math.h
index 8857b418..eef5f2b2 100644
--- a/src/modules/include/math.h
+++ b/src/modules/include/math.h
@@ -141,6 +141,8 @@ long double nearbyintl(long double x);
 
 double      rint(double x);
 double      pow(double x, double y);
+float       powf(float x, float y);
+long double powl(long double x, long double y);
 
 long        lround(double x);
 long        lroundf(float x);
@@ -168,6 +170,14 @@ float       modff(float x, float* i);
 double      modf(double x, double* i);
 long double modfl(long double x, long double* i);
 
+double      cbrt(double x);
+float       cbrtf(float x);
+long double cbrtl(long double x);
+
+double      hypot(double x, double y);
+float       hypotf(float x, float y);
+long double hypotl(long double x, long double y);
+
 #ifdef __cplusplus
 }; // extern "C"
 #endif
diff --git a/src/modules/lib/stdlibc/math/cbrt.c b/src/modules/lib/stdlibc/math/cbrt.c
new file mode 100644
index 00000000..09e32977
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/cbrt.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Hanna Reitz.
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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 <math.h>
+
+double cbrt(double x)
+{
+    return pow(x, 1. / 3.);
+}
+
+float cbrtf(float x)
+{
+    return powf(x, 1.f / 3.f);
+}
+
+long double cbrtl(long double x)
+{
+    return powl(x, 1.L / 3.L);
+}
diff --git a/src/modules/lib/stdlibc/math/hypot.c b/src/modules/lib/stdlibc/math/hypot.c
new file mode 100644
index 00000000..a78f8798
--- /dev/null
+++ b/src/modules/lib/stdlibc/math/hypot.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Hanna Reitz.
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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 <math.h>
+
+double hypot(double x, double y)
+{
+    return sqrt(x * x + y * y);
+}
+
+float hypotf(float x, float y)
+{
+    return sqrtf(x * x + y * y);
+}
+
+long double hypotl(long double x, long double y)
+{
+    return sqrtl(x * x + y * y);
+}
diff --git a/src/modules/lib/stdlibc/math/pow.c b/src/modules/lib/stdlibc/math/pow.c
index b1f791ae..96856ffb 100644
--- a/src/modules/lib/stdlibc/math/pow.c
+++ b/src/modules/lib/stdlibc/math/pow.c
@@ -28,8 +28,37 @@
 
 #include <math.h>
 
+long double powl(long double x, long double y)
+{
+    long double res;
+
+    __asm__ __volatile__ (
+        // ST(0) == x; ST(1) == y
+        "fld1;"
+        // ST(0) == 1; ST(1) == x; ST(2) == y
+        "fxch;"
+        // ST(0) == x; ST(1) == 1; ST(2) == y
+        "fyl2x;"
+        // ST(0) == log2(x); ST(1) == y
+        "fmulp;"
+        // ST(0) == y * log2(x)
+        "f2xm1;"
+        // ST(0) == 2^(y * log2(x)) - 1 == x^y - 1
+        "fld1;"
+        // ST(0) == 1; ST(1) == x^y - 1
+        "faddp"
+        // ST(0) == x^y
+        : "=t"(res) : "0"(x), "u"(y));
+
+    return res;
+}
+
 double pow(double x, double y)
 {
-    return exp(y * log(x));
+    return powl(x, y);
 }
 
+float powf(float x, float y)
+{
+    return powl(x, y);
+}
-- 
2.31.0

