From 7d8786613e76c228affc58bcf01790a10f3c9367 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Wed, 22 Jul 2020 14:38:24 -0400
Subject: [PATCH] port from Vanilla: pow~ raising negative numbers to integer
 powers

---
 pd/src/d_math.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/pd/src/d_math.c b/pd/src/d_math.c
index 59e6d989b..e90984938 100644
--- a/pd/src/d_math.c
+++ b/pd/src/d_math.c
@@ -660,12 +660,10 @@ t_int *pow_tilde_perform(t_int *w)
     int n = (int)(w[4]);
     while (n--)
     {
-        t_float f = *in1++;
-        if (f > 0)
-            *out = pow(f, *in2);
-        else *out = 0;
-        out++;
-        in2++;
+        t_sample f1 = *in1++, f2 = *in2++;
+        *out++ = (f1 == 0 && f2 < 0) ||
+            (f1 < 0 && (f2 - (int)f2) != 0) ?
+            0 : pow(f1, f2);
     }
     return (w+5);
 }
@@ -678,11 +676,10 @@ t_int *scalarpow_tilde_perform(t_int *w)
     int n = (int)(w[4]);
     while (n--)
     {
-        t_float f = *in++;
-        if (f > 0)
-            *out = pow(f, g);
-        else *out = 0;
-        out++;
+        t_sample f1 = *in++;
+        *out++ = (f1 == 0 && g < 0) ||
+            (f1 < 0 && (g - (int)g) != 0) ?
+            0 : pow(f1, g);
     }
     return(w+5);
 }
-- 
GitLab