Quellcode durchsuchen

fix https://github.com/pocketpy/pocketpy/issues/211

blueloveTH vor 2 Jahren
Ursprung
Commit
0599130c0d
6 geänderte Dateien mit 23 neuen und 8 gelöschten Zeilen
  1. 1 1
      amalgamate.py
  2. 2 0
      cmake_build.py
  3. 0 0
      include/pocketpy/_generated.h
  4. 3 4
      python/cmath.py
  5. 5 2
      src/str.cpp
  6. 12 1
      tests/10_cmath.py

+ 1 - 1
amalgamate.py

@@ -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'

+ 2 - 0
cmake_build.py

@@ -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")
 

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
include/pocketpy/_generated.h


+ 3 - 4
python/cmath.py

@@ -12,15 +12,14 @@ class complex:
     @property
     def imag(self):
         return self._imag
-    
+
     def conjugate(self):
         return complex(self.real, -self.imag)
     
     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)
     

+ 5 - 2
src/str.cpp

@@ -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){

+ 12 - 1
tests/10_cmath.py

@@ -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

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.