mirror of
https://github.com/zrax/pycdc.git
synced 2026-06-23 11:34:07 +00:00
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:
parent
870ecdc430
commit
ed11ba3fe4
1 changed files with 13 additions and 2 deletions
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue