txlyre 1 giorno fa
parent
commit
674767ab69
2 ha cambiato i file con 364 aggiunte e 244 eliminazioni
  1. 334 244
      qistd.c
  2. 30 0
      std.qi

File diff suppressed because it is too large
+ 334 - 244
qistd.c


+ 30 - 0
std.qi

@@ -453,6 +453,36 @@ func __class_wrapper(n, p, t, mt, st): return Object({
         return obj
     }
 }, nil, st)
+func hex(x) {
+    if type(x) != "number"
+      throw "expected first argument to be: number, but got: " + type(x)
+    if x == 0
+      return "0x0"
+    let sgn = x < 0
+    if sgn 
+      x = -x
+    var r = ""
+    for x > 0 {
+        r = "0123456789abcdef"[x % 16] + r
+        x //= 16
+    }
+    return (sgn? "-0x": "0x") + r
+}
+func oct(x) {
+    if type(x) != "number"
+      throw "expected first argument to be: number, but got: " + type(x)
+    if x == 0
+      return "0o0"
+    let sgn = x < 0
+    if sgn 
+      x = -x
+    var r = ""
+    for x > 0 {
+        r = "01234567"[x % 8] + r
+        x //= 8
+    }
+    return (sgn? "-0o": "0o") + r
+}
 func format(s) {
   if type(s) != "string"
     throw "expected first argument to be: string, but got: " + type(s)

Some files were not shown because too many files changed in this diff