Refactors how we handle NaN and infinity
The previous approach didn't work properly under MSVC. The wrong output would be produced for NaN values. This new approach will directly print out "nan" and "inf" with the appropriate sign, rather than just wrapping the value in float('').
This commit is contained in:
15
bytecode.cpp
15
bytecode.cpp
@@ -272,8 +272,19 @@ void print_const(PycRef<PycObject> obj, PycModule* mod)
|
||||
{
|
||||
// Wrap any nan/inf values in float('').
|
||||
double value = obj.cast<PycCFloat>()->value();
|
||||
if (std::isnan(value) || std::isinf(value)) {
|
||||
fprintf(pyc_output, "float('%g')", value);
|
||||
bool is_negative = std::signbit(value);
|
||||
if (std::isnan(value)) {
|
||||
if (is_negative) {
|
||||
fprintf(pyc_output, "float('-nan')");
|
||||
} else {
|
||||
fprintf(pyc_output, "float('nan')");
|
||||
}
|
||||
} else if (std::isinf(value)) {
|
||||
if (is_negative) {
|
||||
fprintf(pyc_output, "float('-inf')");
|
||||
} else {
|
||||
fprintf(pyc_output, "float('inf')");
|
||||
}
|
||||
} else {
|
||||
fprintf(pyc_output, "%g", value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user