File tree 2 files changed +15
-5
lines changed
torch/csrc/jit/tensorexpr
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,14 @@ TEST(IRPrinter, BasicValueTest02) {
37
37
ASSERT_EQ (ss.str (), " (2.f + 3.f) - (4.f + 5.f)" );
38
38
}
39
39
40
+ TEST (IRPrinter, BasicValueTest03) {
41
+ ExprHandle a (3 .402823466385289e+38f );
42
+ ExprHandle b (-3 .402823466385289e+38f );
43
+ std::stringstream ss;
44
+ ss << a << " , " << b;
45
+ ASSERT_EQ (ss.str (), " 3.402823466385289e+38f, -3.402823466385289e+38f" );
46
+ }
47
+
40
48
TEST (IRPrinter, CastTest) {
41
49
VarHandle x (" x" , kHalf );
42
50
VarHandle y (" y" , kFloat );
Original file line number Diff line number Diff line change @@ -191,25 +191,27 @@ void IRPrinter::visit(const CompareSelectPtr& v) {
191
191
withParens (v->ret_val2 ());
192
192
}
193
193
194
- static void formatFPSuffix (std::ostream& os, double v) {
195
- os << (v == std::ceil (v) ? " .0" : " " );
194
+ static void formatFPSuffix (std::ostream& os, double v, bool flag ) {
195
+ os << (flag && v == std::ceil (v) ? " .0" : " " );
196
196
}
197
197
198
198
template <typename T>
199
- static void formatFPSuffix (std::ostream& os, T v) {
200
- os << (v == std::ceil (v) ? " .f" : " f" );
199
+ static void formatFPSuffix (std::ostream& os, T v, bool flag ) {
200
+ os << (flag && v == std::ceil (v) ? " .f" : " f" );
201
201
}
202
202
203
203
template <typename T, std::enable_if_t <std::is_floating_point_v<T>>* = nullptr >
204
204
static void formatImm (std::ostream& os, T v) {
205
205
const int precision = 16 ;
206
+ const T lower_bound = static_cast <T>(-std::pow (10 , precision));
207
+ const T upper_bound = -lower_bound;
206
208
if (std::isnan (v)) {
207
209
os << " NAN" ;
208
210
} else if (std::isinf (v)) {
209
211
os << (v > 0 ? " POS_INFINITY" : " NEG_INFINITY" );
210
212
} else {
211
213
os << std::setprecision (precision) << v;
212
- formatFPSuffix (os, v);
214
+ formatFPSuffix (os, v, v > lower_bound && v < upper_bound );
213
215
}
214
216
}
215
217
You can’t perform that action at this time.
0 commit comments