Index: src/wasm/wasm-interpreter.cc |
diff --git a/src/wasm/wasm-interpreter.cc b/src/wasm/wasm-interpreter.cc |
index c8a257e569b920e918eb77c7c7209b1c79ccf795..aabf4105634f0de9723c6f5b88810eb4e3855c6b 100644 |
--- a/src/wasm/wasm-interpreter.cc |
+++ b/src/wasm/wasm-interpreter.cc |
@@ -352,13 +352,23 @@ static inline double ExecuteF64Sub(double a, double b, TrapReason* trap) { |
static inline double ExecuteF64Min(double a, double b, TrapReason* trap) { |
if (std::isnan(a)) return quiet(a); |
if (std::isnan(b)) return quiet(b); |
- return std::min(a, b); |
+ if ((a == 0.0) && (b == 0.0) && (copysign(1.0, a) != copysign(1.0, b))) { |
+ // a and b are zero, and the sign differs: return -0.0. |
+ return -0.0; |
+ } else { |
+ return (a < b) ? a : b; |
+ } |
} |
static inline double ExecuteF64Max(double a, double b, TrapReason* trap) { |
if (std::isnan(a)) return quiet(a); |
if (std::isnan(b)) return quiet(b); |
- return std::max(a, b); |
+ if ((a == 0.0) && (b == 0.0) && (copysign(1.0, a) != copysign(1.0, b))) { |
+ // a and b are zero, and the sign differs: return 0.0. |
+ return 0.0; |
+ } else { |
+ return (a > b) ? a : b; |
+ } |
} |
static inline double ExecuteF64CopySign(double a, double b, TrapReason* trap) { |