mirror of
https://github.com/zrax/pycdc.git
synced 2026-06-23 11:34:07 +00:00
Handle NaN and infinity values
Right now, NaN/infinity values will produce "nan" and "inf", but
Python doesn't allow those in source code. This change will wrap
those values in float(''), which is allowed.
Tests for Python 2.7 and 3.8 have been added as well.
Fixes #136
This commit is contained in:
parent
36d93bd1a5
commit
870ecdc430
5 changed files with 26 additions and 1 deletions
11
bytecode.cpp
11
bytecode.cpp
|
|
@ -1,5 +1,6 @@
|
|||
#include "pyc_numeric.h"
|
||||
#include "bytecode.h"
|
||||
#include <cmath>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
|
|
@ -268,7 +269,15 @@ void print_const(PycRef<PycObject> obj, PycModule* mod)
|
|||
obj.cast<PycComplex>()->imag());
|
||||
break;
|
||||
case PycObject::TYPE_BINARY_FLOAT:
|
||||
fprintf(pyc_output, "%g", obj.cast<PycCFloat>()->value());
|
||||
{
|
||||
// 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);
|
||||
} else {
|
||||
fprintf(pyc_output, "%g", value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PycObject::TYPE_BINARY_COMPLEX:
|
||||
fprintf(pyc_output, "(%g+%gj)", obj.cast<PycCComplex>()->value(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue