blueloveTH 2024-02-23 01:27:48 +08:00
parent 842c415a9f
commit 0599130c0d
6 changed files with 24 additions and 9 deletions

View File

@ -1,6 +1,6 @@
import os
os.system("python3 prebuild.py")
assert os.system("python prebuild.py") == 0
with open("include/pocketpy/opcodes.h", "rt", encoding='utf-8') as f:
OPCODES_TEXT = '\n' + f.read() + '\n'

View File

@ -2,6 +2,8 @@ import os
import sys
import shutil
assert os.system("python prebuild.py") == 0
if not os.path.exists("build"):
os.mkdir("build")

File diff suppressed because one or more lines are too long

View File

@ -18,9 +18,8 @@ class complex:
def __repr__(self):
s = ['(', str(self.real)]
if self.imag >= 0:
s.append('+')
s.append(str(self.imag))
s.append('-' if self.imag < 0 else '+')
s.append(str(abs(self.imag)))
s.append('j)')
return ''.join(s)

View File

@ -505,8 +505,11 @@ int utf8len(unsigned char c, bool suppress){
}
SStream& SStream::operator<<(f64 val){
if(std::isinf(val) || std::isnan(val)){
return (*this) << std::to_string(val);
if(std::isinf(val)){
return (*this) << (val > 0 ? "inf" : "-inf");
}
if(std::isnan(val)){
return (*this) << "nan";
}
char b[32];
if(_precision == -1){

View File

@ -1,4 +1,5 @@
from cmath import isclose, sqrt
from cmath import isclose, sqrt, nan, inf, nanj, infj
import math
assert 1+2j == complex(1, 2) == 2j+1
@ -25,3 +26,13 @@ assert repr(1+2j) == '(1.0+2.0j)'
assert repr(1+0j) == '(1.0+0.0j)'
assert repr(-1-3j) == '(-1.0-3.0j)'
assert repr(1-3j) == '(1.0-3.0j)'
assert repr(math.nan) == repr(nan) == 'nan'
assert repr(-math.nan) == repr(-nan) == 'nan'
assert repr(math.inf) == repr(inf) == 'inf'
assert repr(-math.inf) == repr(-inf) == '-inf'
assert repr(nanj) == '(0.0+nanj)', nanj
assert repr(-nanj) == '(0.0+nanj)', -nanj
assert repr(infj) == '(0.0+infj)', infj
assert repr(-infj) == '(0.0-infj)', -infj