Skip to content

Commit 3278896

Browse files
CEL Dev Teamcopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 943161734
1 parent 2b84002 commit 3278896

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

runtime/standard/arithmetic_functions.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "runtime/standard/arithmetic_functions.h"
1616

17+
#include <cmath>
1718
#include <cstdint>
1819
#include <limits>
1920

@@ -139,6 +140,17 @@ Value Div<double>(double v0, double v1) {
139140
static_assert(std::numeric_limits<double>::is_iec559,
140141
"Division by zero for doubles must be supported");
141142

143+
if (v1 == 0.0) {
144+
if (v0 == 0.0 || std::isnan(v0)) {
145+
return DoubleValue(std::numeric_limits<double>::quiet_NaN());
146+
}
147+
double inf = std::numeric_limits<double>::infinity();
148+
if (std::signbit(v0) != std::signbit(v1)) {
149+
return DoubleValue(-inf);
150+
}
151+
return DoubleValue(inf);
152+
}
153+
142154
// For double, division will result in +/- inf
143155
return DoubleValue(v0 / v1);
144156
}

0 commit comments

Comments
 (0)