shithub: npe

Download patch

ref: ffcac5481aa489250d0752f69c1bbbf0f0ae1977
parent: dcb29f7e9714e539ce32f0aa06287471c349892f
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Aug 16 21:18:55 EDT 2023

npe: add fmax

--- a/include/npe/math.h
+++ b/include/npe/math.h
@@ -56,5 +56,6 @@
 
 double acosh(double x);
 double log1p(double x);
+double fmax(double x, double y);
 
 #endif
--- /dev/null
+++ b/libnpe/fmax.c
@@ -1,0 +1,16 @@
+#include <math.h>
+/* taken from musl */
+
+#define _sign(d) (*((u64int*)d) & (1ULL<<63))
+
+double
+fmax(double x, double y)
+{
+	if(isNaN(x))
+		return y;
+	if(isNaN(y))
+		return x;
+	if(_sign(&x) != _sign(&y))
+		return _sign(&x) ? y : x;
+	return x < y ? y : x;
+}