|
@@ -453,6 +453,36 @@ func __class_wrapper(n, p, t, mt, st): return Object({
|
|
|
return obj
|
|
return obj
|
|
|
}
|
|
}
|
|
|
}, nil, st)
|
|
}, 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) {
|
|
func format(s) {
|
|
|
if type(s) != "string"
|
|
if type(s) != "string"
|
|
|
throw "expected first argument to be: string, but got: " + type(s)
|
|
throw "expected first argument to be: string, but got: " + type(s)
|