SHA256
3
0
forked from pool/gawk
gawk/nan-sign.patch

51 lines
1.2 KiB
Diff
Raw Normal View History

diff --git a/eval.c b/eval.c
index 1069570b7..44f614d22 100644
--- a/eval.c
+++ b/eval.c
@@ -39,6 +39,8 @@ static int num_exec_hook = 0;
static Func_pre_exec pre_execute[MAX_EXEC_HOOKS];
static Func_post_exec post_execute = NULL;
+static double fix_nan_sign(double left, double right, double result);
+
extern void frame_popped();
int OFSlen;
@@ -1901,3 +1903,16 @@ elem_new_to_scalar(NODE *n)
return n;
}
+
+/* fix_nan_sign --- fix NaN sign on RiscV */
+
+static double
+fix_nan_sign(double left, double right, double result)
+{
+ if (isnan(left) && signbit(left))
+ return copysign(result, -1.0);
+ else if (isnan(right) && signbit(right))
+ return copysign(result, -1.0);
+ else
+ return result;
+}
diff --git a/interpret.h b/interpret.h
index 26010ada1..955d918f1 100644
--- a/interpret.h
+++ b/interpret.h
@@ -583,6 +583,7 @@ uninitialized_scalar:
plus:
t1 = TOP_NUMBER();
r = make_number(t1->numbr + x2);
+ r->numbr = fix_nan_sign(t1->numbr, x2, r->numbr);
DEREF(t1);
REPLACE(r);
break;
@@ -597,6 +598,7 @@ plus:
minus:
t1 = TOP_NUMBER();
r = make_number(t1->numbr - x2);
+ r->numbr = fix_nan_sign(t1->numbr, x2, r->numbr);
DEREF(t1);
REPLACE(r);
break;