summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-08-14 20:56:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-08-14 20:56:54 -0700
commit725112ef78d8c6e655db4a99fc69e54d0ed1eb5a (patch)
tree89b456d55b28fb07a41483aa838555ee3035c1a5
parentf94ae27b4021b61eabe50d3b088b8d8917bfdfe8 (diff)
downloadtxr-725112ef78d8c6e655db4a99fc69e54d0ed1eb5a.tar.gz
txr-725112ef78d8c6e655db4a99fc69e54d0ed1eb5a.tar.bz2
txr-725112ef78d8c6e655db4a99fc69e54d0ed1eb5a.zip
math: tofloat and toint in user-defined arithmetic.
* arith.c (tofloat_s, toint_s): New symbol variables. (tofloat, toint): If the argument is a COBJ, handle it via do_unary_method. (arith_init): Initialize new symbol variables. The functions tofloat, toint, tofloatz and tointz. are now registered here, rather than eval_init. * eval.c (eval_init): Remove registrations of tofloat, toint, tofloatz and tointz. * tests/016/ud-arith.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
-rw-r--r--arith.c19
-rw-r--r--eval.c4
-rw-r--r--stdlib/doc-syms.tl238
-rw-r--r--tests/016/ud-arith.tl6
-rw-r--r--txr.131
5 files changed, 172 insertions, 126 deletions
diff --git a/arith.c b/arith.c
index e058560a..850358d0 100644
--- a/arith.c
+++ b/arith.c
@@ -84,6 +84,8 @@ val r_copysign_s, r_drem_s, r_fdim_s, r_fmax_s, r_fmin_s, r_hypot_s;
val r_jn_s, r_ldexp_s, r_nextafter_s, r_remainder_s, r_scalb_s;
val r_scalbln_s, r_yn_s;
+val tofloat_s, toint_s;
+
val make_bignum(void)
{
val n = make_obj();
@@ -4358,6 +4360,8 @@ val n_perm_k(val n, val k)
val tofloat(val obj)
{
+ val self = tofloat_s;
+
switch (tag(obj)) {
case TAG_NUM:
return flo_int(obj);
@@ -4385,13 +4389,16 @@ val tofloat(val obj)
}
/* fallthrough */
default:
- uw_throwf(error_s, lit("tofloat: ~s is not convertible to float"), obj, nao);
+ if (type(obj) == COBJ)
+ return do_unary_method(self, self, obj);
+ uw_throwf(error_s, lit("~s: ~s is not convertible to float"),
+ self, obj, nao);
}
}
val toint(val obj, val base)
{
- val self = lit("toint");
+ val self = toint_s;
switch (tag(obj)) {
case TAG_NUM:
@@ -4429,6 +4436,8 @@ val toint(val obj, val base)
}
/* fallthrough */
default:
+ if (type(obj) == COBJ)
+ return do_unary_method(self, self, obj);
uw_throwf(error_s, lit("~a: ~s is not convertible to integer"),
self, obj, nao);
}
@@ -5366,6 +5375,8 @@ void arith_init(void)
width_s = intern(lit("width"), user_package);
bitset_s = intern(lit("bitset"), user_package);
logcount_s = intern(lit("logcount"), user_package);
+ tofloat_s = intern(lit("tofloat"), user_package);
+ toint_s = intern(lit("toint"), user_package);
reg_varl(intern(lit("flo-dig"), user_package), num_fast(DBL_DIG));
reg_varl(intern(lit("flo-max-dig"), user_package), num_fast(FLO_MAX_DIG));
@@ -5384,6 +5395,10 @@ void arith_init(void)
#endif
reg_varl(intern(lit("%e%"), user_package), flo(M_E));
+ reg_fun(tofloat_s, func_n1(tofloat));
+ reg_fun(toint_s, func_n2o(toint, 1));
+ reg_fun(intern(lit("tofloatz"), user_package), func_n1(tofloatz));
+ reg_fun(intern(lit("tointz"), user_package), func_n2o(tointz, 1));
reg_fun(plus_s, func_n0v(plusv));
reg_fun(minus_s, func_n1v(minusv));
reg_fun(mul_s, func_n0v(mulv));
diff --git a/eval.c b/eval.c
index 094ecb71..adfd6d69 100644
--- a/eval.c
+++ b/eval.c
@@ -7609,10 +7609,6 @@ void eval_init(void)
reg_fun(intern(lit("num-str"), user_package), func_n1(num_str));
reg_fun(intern(lit("int-flo"), user_package), func_n1(int_flo));
reg_fun(intern(lit("flo-int"), user_package), func_n1(flo_int));
- reg_fun(intern(lit("tofloat"), user_package), func_n1(tofloat));
- reg_fun(intern(lit("toint"), user_package), func_n2o(toint, 1));
- reg_fun(intern(lit("tofloatz"), user_package), func_n1(tofloatz));
- reg_fun(intern(lit("tointz"), user_package), func_n2o(tointz, 1));
reg_fun(intern(lit("less"), user_package), func_n1v(lessv));
reg_fun(intern(lit("greater"), user_package), func_n1v(greaterv));
reg_fun(intern(lit("lequal"), user_package), func_n1v(lequalv));
diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl
index 42f92032..a48a691a 100644
--- a/stdlib/doc-syms.tl
+++ b/stdlib/doc-syms.tl
@@ -4,7 +4,7 @@
("%e%" "N-03F0FA9E")
("%fun%" "N-00719365")
("%pi%" "N-03F0FA9E")
- ("*" "D-0087")
+ ("*" "D-0089")
("*args*" "N-03DEE18A")
("*args-eff*" "N-03DEE18A")
("*args-full*" "N-03DEE18A")
@@ -54,8 +54,8 @@
("*trace-output*" "N-0067A6AC")
("*tree-fun-whitelist*" "N-025AB9C9")
("*unhandled-hook*" "N-02B4A4FB")
- ("+" "D-0059")
- ("-" "D-008A")
+ ("+" "D-005A")
+ ("-" "D-008C")
("--" "N-0234C408")
("--rng" "N-01A056E4")
("--rng+" "N-01A056E4")
@@ -65,29 +65,29 @@
("-rng" "N-01A056E4")
("-rng+" "N-01A056E4")
("-rng-" "N-01A056E4")
- ("/" "D-005C")
+ ("/" "D-005D")
("//" "N-0054C409")
("/=" "N-003BE40C")
(":delegate" "N-037F664C")
(":key" "N-01697547")
(":mass-delegate" "N-000BBDEA")
(":match" "N-03B92C0D")
- ("<" "D-008E")
+ ("<" "D-0090")
("<!" "N-02B10DF9")
("<-" "N-02B10DF9")
("<=" "D-0008")
- ("=" "D-0070")
- (">" "D-0034")
- (">=" "D-008D")
+ ("=" "D-0072")
+ (">" "D-0035")
+ (">=" "D-008F")
("abort" "N-02F934F6")
- ("abs" "D-0022")
+ ("abs" "D-0023")
("abs-path-p" "N-00477B23")
("accept" "D-0011")
("acons" "N-02E9343D")
("acons-new" "N-0371BAFA")
("aconsql-new" "N-01E315BD")
- ("acos" "D-0026")
- ("acosh" "D-002D")
+ ("acos" "D-0027")
+ ("acosh" "D-002E")
("add" "N-03244398")
("add*" "N-03244398")
("add-suffix" "N-00AE9981")
@@ -108,10 +108,10 @@
("alignof" "N-000F730E")
("alist-nremove" "N-000CD07F")
("alist-remove" "N-001A53C4")
- ("all" "D-0031")
+ ("all" "D-0032")
("all*" "N-00F6E2A2")
("allocate-struct" "N-03168BF2")
- ("and" "D-0092")
+ ("and" "D-0094")
("andf" "N-01E7D2AD")
("ap" "N-011CFC0C")
("apf" "N-012A7E6A")
@@ -130,16 +130,16 @@
("array" "N-0117BE95")
("arraysize" "N-002129D6")
("as" "N-028B26DD")
- ("ash" "D-0065")
- ("asin" "D-0057")
+ ("ash" "D-0067")
+ ("asin" "D-0058")
("asinh" "D-001E")
- ("assert" "D-0091")
+ ("assert" "D-0093")
("assoc" "N-00E9306D")
("assq" "N-00123702")
("assql" "N-00123702")
("at-exit-call" "N-003EEEF5")
("at-exit-do-not-call" "N-003EEEF5")
- ("atan" "D-008C")
+ ("atan" "D-008E")
("atan2" "D-0020")
("atanh" "D-000B")
("atom" "N-0076C7BE")
@@ -160,11 +160,11 @@
("bignump" "N-03E9D6E1")
("bind" "D-0019")
("bindable" "N-0222F2E3")
- ("bit" "D-002F")
- ("bitset" "D-0029")
+ ("bit" "D-0030")
+ ("bitset" "D-002A")
("blkcnt-t" "N-01153D9E")
("blksize-t" "N-01153D9E")
- ("block" "D-0039")
+ ("block" "D-003A")
("block*" "N-02F60DCE")
("bool" "D-000C")
("boundp" "N-01FBF828")
@@ -181,7 +181,7 @@
("buf-alloc-size" "N-013A3727")
("buf-carray" "N-0022F54E")
("buf-compress" "N-02DB9DFB")
- ("buf-d" "D-0048")
+ ("buf-d" "D-0049")
("buf-decompress" "N-02DB9DFB")
("buf-get-char" "N-03E9074A")
("buf-get-cptr" "N-00E90766")
@@ -245,7 +245,7 @@
("call-super-method" "N-016185D1")
("call-update-expander" "N-03B6BCE9")
("callf" "N-00192C21")
- ("car" "D-0025")
+ ("car" "D-0026")
("carray" "N-0139F9ED")
("carray-blank" "N-00DD8DF1")
("carray-buf" "N-00D75AD6")
@@ -282,7 +282,7 @@
("cat-str" "N-00B6ACE3")
("cat-streams" "N-020BF082")
("cat-vec" "N-01AEB28B")
- ("catch" "D-0078")
+ ("catch" "D-007A")
("catch*" "N-0211F3D3")
("catch**" "N-0211F3D3")
("catch-frame" "N-0233BAE3")
@@ -295,7 +295,7 @@
("cdddddr" "N-001FA3CB")
("cddr" "N-001FA3CB")
("cdr" "D-001C")
- ("ceil" "D-003E")
+ ("ceil" "D-003F")
("ceil-rem" "N-02DE978F")
("ceil1" "N-02C8FF28")
("chain" "N-00C53CF7")
@@ -334,7 +334,7 @@
("clean-file" "N-001939D4")
("clear-cflags" "N-02061924")
("clear-dirty" "N-03AB857D")
- ("clear-error" "D-0045")
+ ("clear-error" "D-0046")
("clear-iflags" "N-02061924")
("clear-lflags" "N-02061924")
("clear-mask" "N-0269D998")
@@ -344,7 +344,7 @@
("clocal" "N-01B1B5DF")
("clock-t" "N-01B6F219")
("clockid-t" "N-01153D9E")
- ("close" "D-007C")
+ ("close" "D-007E")
("close-lazy-streams" "N-00B8ACD5")
("close-stream" "N-00596930")
("closedir" "N-01FEE88A")
@@ -354,7 +354,7 @@
("cmspar" "N-01B1B5DF")
("cnsort" "N-02102493")
("coded-length" "N-0167F423")
- ("coll" "D-0062")
+ ("coll" "D-0063")
("collect" "D-000E")
("collect-each" "N-0105F01D")
("collect-each*" "N-0105F01D")
@@ -415,14 +415,14 @@
("copy-vec" "N-010E7635")
("copysign" "N-035C06D4")
("cos" "D-000A")
- ("cosh" "D-0096")
+ ("cosh" "D-0098")
("count" "N-00AE0CB6")
("count-if" "N-00AE0CB6")
("count-until-match" "N-00EFD668")
("countq" "N-01DF131F")
("countql" "N-01DF131F")
("countqual" "N-01DF131F")
- ("cptr" "D-0079")
+ ("cptr" "D-007B")
("cptr-buf" "N-037139E3")
("cptr-carray" "N-02257F04")
("cptr-cast" "N-01A212ED")
@@ -492,7 +492,7 @@
("defun-match" "N-02BF0F8C")
("defvar" "N-039DD0E7")
("defvarl" "N-03F36A75")
- ("del" "D-004B")
+ ("del" "D-004C")
("del*" "N-0166445C")
("delay" "N-00DCE524")
("delcons" "N-03A1ABA8")
@@ -514,7 +514,7 @@
("dlsym-checked" "N-029063A0")
("dlvsym" "N-01B1E865")
("dlvsym-checked" "N-029063A0")
- ("do" "D-006D")
+ ("do" "D-006F")
("doc" "N-0097F54C")
("dohash" "N-039105E8")
("doloop" "N-01FF4DDB")
@@ -538,7 +538,7 @@
("dump-deferred-warnings" "N-0335651E")
("dup" "N-0387F549")
("dupfd" "N-01F91AEF")
- ("dwim" "D-007F")
+ ("dwim" "D-0081")
("e2big" "N-036B1BDB")
("eacces" "N-036B1BDB")
("each" "N-0105F01D")
@@ -593,7 +593,7 @@
("eisconn" "N-036B1BDB")
("eisdir" "N-036B1BDB")
("elemsize" "N-01D55CC4")
- ("elemtype" "D-0044")
+ ("elemtype" "D-0045")
("eloop" "N-036B1BDB")
("emfile" "N-036B1BDB")
("emlink" "N-036B1BDB")
@@ -653,13 +653,13 @@
("eprototype" "N-036B1BDB")
("eq" "N-02550B35")
("eql" "N-02550B35")
- ("equal" "D-003D")
+ ("equal" "D-003E")
("equot" "N-02ACCDDF")
("erange" "N-036B1BDB")
- ("erf" "D-0043")
- ("erfc" "D-007E")
+ ("erf" "D-0044")
+ ("erfc" "D-0080")
("erofs" "N-036B1BDB")
- ("errno" "D-003C")
+ ("errno" "D-003D")
("error" "N-015466AD")
("espipe" "N-036B1BDB")
("esrch" "N-036B1BDB")
@@ -678,17 +678,17 @@
("exec" "N-02D6C913")
("exit" "N-0006C92F")
("exit*" "N-03592671")
- ("exp" "D-0084")
- ("exp10" "D-0049")
- ("exp2" "D-003A")
+ ("exp" "D-0086")
+ ("exp10" "D-004A")
+ ("exp2" "D-003B")
("expand" "N-00EBC996")
("expand*" "N-00EBC996")
("expand-left" "N-00E168FE")
("expand-right" "N-023B6B64")
("expand-with-free-refs" "N-0334827B")
("expander-let" "N-00DBD46D")
- ("expm1" "D-0033")
- ("expt" "D-0093")
+ ("expm1" "D-0034")
+ ("expt" "D-0095")
("exptmod" "D-000F")
("extproc" "N-0072FF5E")
("f" "N-003BDFA9")
@@ -749,12 +749,12 @@
("file-get-string" "N-02238370")
("file-put" "N-0041C2E5")
("file-put-buf" "N-02AE3A31")
- ("file-put-json" "D-0027")
- ("file-put-jsons" "D-0073")
+ ("file-put-json" "D-0028")
+ ("file-put-jsons" "D-0075")
("file-put-lines" "N-0041C2E5")
("file-put-string" "N-0041C2E5")
("fileno" "N-008ACF75")
- ("fill-buf" "D-004D")
+ ("fill-buf" "D-004E")
("fill-buf-adjust" "N-00D142E1")
("fill-carray" "N-00737951")
("fill-obj" "N-0039A1D1")
@@ -763,7 +763,7 @@
("filter-equal" "N-03136087")
("filter-string-tree" "N-00C9EEB0")
("finalize" "N-01230613")
- ("finally" "D-0071")
+ ("finally" "D-0073")
("find" "N-00C9DFF6")
("find-frame" "N-02B97226")
("find-frames" "N-02B97226")
@@ -804,7 +804,7 @@
("float" "N-03237030")
("floatp" "N-03E9D6E1")
("flock" "N-004E5B3E")
- ("floor" "D-0082")
+ ("floor" "D-0084")
("floor-rem" "N-02DE978F")
("floor1" "N-01ED20D1")
("flow" "N-0178C76B")
@@ -873,7 +873,7 @@
("fuzz" "N-03CAE17D")
("fw" "N-0357AE6F")
("gamma" "D-001A")
- ("gather" "D-004F")
+ ("gather" "D-0050")
("gcd" "N-03D44645")
("gen" "N-0323BEBD")
("gen-hash-seed" "N-002CFA72")
@@ -882,10 +882,10 @@
("gequal" "N-00A3E42D")
("get" "N-03D9F55D")
("get-buf-from-stream" "N-02954B48")
- ("get-byte" "D-0037")
- ("get-char" "D-0067")
- ("get-error" "D-0028")
- ("get-error-str" "D-0077")
+ ("get-byte" "D-0038")
+ ("get-char" "D-0069")
+ ("get-error" "D-0029")
+ ("get-error-str" "D-0079")
("get-fd" "N-011D42AB")
("get-frames" "N-010405DA")
("get-hash-userdata" "N-030B41A7")
@@ -954,7 +954,7 @@
("handle*" "N-03F7D8B5")
("handle-frame" "N-0233BAE3")
("handler-bind" "N-00A4ECC9")
- ("hash" "D-0041")
+ ("hash" "D-0042")
("hash-alist" "N-00C9B125")
("hash-begin" "N-0225209D")
("hash-construct" "N-017E6F4C")
@@ -1002,7 +1002,7 @@
("identity*" "N-004834CC")
("ido" "N-011CFC0C")
("iexten" "N-0072FF5E")
- ("if" "D-0024")
+ ("if" "D-0025")
("if-match" "N-01BE5C4A")
("ifa" "N-018F39B0")
("iff" "N-000E3A74")
@@ -1078,11 +1078,11 @@
("isig" "N-0072FF5E")
("isqrt" "D-0010")
("istrip" "N-02391683")
- ("iter-begin" "D-0050")
+ ("iter-begin" "D-0051")
("iter-item" "D-0001")
- ("iter-more" "D-002A")
+ ("iter-more" "D-002B")
("iter-reset" "D-0009")
- ("iter-step" "D-006C")
+ ("iter-step" "D-006E")
("iterable" "N-01156AE3")
("itimer-prof" "N-02B7882A")
("itimer-real" "N-02B7882A")
@@ -1092,8 +1092,8 @@
("ixany" "N-02391683")
("ixoff" "N-02391683")
("ixon" "N-02391683")
- ("j0" "D-0094")
- ("j1" "D-0064")
+ ("j0" "D-0096")
+ ("j1" "D-0065")
("jn" "N-035C06D4")
("join" "N-00B6ACE3")
("join-with" "N-00B6ACE3")
@@ -1115,10 +1115,10 @@
("kill" "N-0386CCD5")
("krs" "N-02D33A4D")
("labels" "N-0209307D")
- ("lambda" "D-0083")
+ ("lambda" "D-0085")
("lambda-match" "N-031E43FF")
("lambda-set" "N-02FEBA97")
- ("last" "D-0058")
+ ("last" "D-0059")
("lazy-str" "N-02AFF63D")
("lazy-str-force" "N-03269DEF")
("lazy-str-force-upto" "N-0212FED6")
@@ -1137,7 +1137,7 @@
("ldo" "N-03EF3A27")
("left" "N-020D5C1D")
("len" "N-03AD172A")
- ("length" "D-005B")
+ ("length" "D-005C")
("length-buf" "N-0026D89A")
("length-carray" "N-03FF97BD")
("length-list" "N-01F8186A")
@@ -1159,7 +1159,7 @@
("lexical-symacro-p" "N-021EC6D2")
("lexical-var-p" "N-021EC6D2")
("lflow" "N-0178C76B")
- ("lgamma" "D-0086")
+ ("lgamma" "D-0088")
("lib-version" "N-032F57D4")
("line" "N-02D5D09D")
("link" "N-009EF0C8")
@@ -1173,14 +1173,14 @@
("listp" "N-03F70343")
("lnew" "N-0230059D")
("lnew*" "N-021E6FDC")
- ("load" "D-0040")
+ ("load" "D-0041")
("load-args-process" "N-03D9382A")
("load-args-recurse" "N-03067356")
("load-for" "N-0020A085")
- ("load-time" "D-0089")
+ ("load-time" "D-008B")
("loand" "N-02C35B52")
("loff-t" "N-01153D9E")
- ("log" "D-005A")
+ ("log" "D-005B")
("log-alert" "N-035D75EC")
("log-auth" "N-0116F48F")
("log-authpriv" "N-0116F48F")
@@ -1199,17 +1199,17 @@
("log-pid" "N-02371913")
("log-user" "N-0116F48F")
("log-warning" "N-035D75EC")
- ("log10" "D-0060")
+ ("log10" "D-0061")
("log1p" "D-001F")
- ("log2" "D-006F")
+ ("log2" "D-0071")
("logand" "D-0021")
- ("logb" "D-006E")
- ("logcount" "D-0055")
- ("logior" "D-008B")
- ("lognot" "D-0047")
+ ("logb" "D-0070")
+ ("logcount" "D-0056")
+ ("logior" "D-008D")
+ ("lognot" "D-0048")
("lognot1" "N-019541E2")
("logtest" "N-00B1548A")
- ("logtrunc" "D-003B")
+ ("logtrunc" "D-003C")
("logxor" "N-02D5AF97")
("long" "N-0235F4E4")
("long-suffix" "N-00A3183A")
@@ -1318,14 +1318,14 @@
("meq" "N-020A0042")
("meql" "N-020A0042")
("mequal" "N-020A0042")
- ("merge" "D-008F")
+ ("merge" "D-0091")
("merge-delete-package" "N-0160EA2C")
("meth" "N-02C216C3")
("method" "N-022200C1")
("mf" "N-036B6E55")
("min" "N-023C3643")
("minor" "N-02F0F482")
- ("minusp" "D-005F")
+ ("minusp" "D-0060")
("mismatch" "N-03164F4F")
("mkdir" "N-00C543B8")
("mkdtemp" "N-026E4871")
@@ -1336,7 +1336,7 @@
("mlet" "N-008216E0")
("mmakunbound" "N-02964FC0")
("mmap" "N-03C6CE44")
- ("mod" "D-002B")
+ ("mod" "D-002C")
("mode-t" "N-01153D9E")
("mprotect" "N-02805A83")
("ms-async" "N-01F782B2")
@@ -1358,7 +1358,7 @@
("ncon" "N-022F6E60")
("ncon*" "N-022F6E60")
("nconc" "N-0014162F")
- ("nearbyint" "D-0023")
+ ("nearbyint" "D-0024")
("neg" "N-02C9F5F9")
("neq" "N-0216A942")
("neql" "N-0216A942")
@@ -1366,7 +1366,7 @@
("new" "N-0230059D")
("new*" "N-021E6FDC")
("nexpand-left" "N-00E168FE")
- ("next" "D-006A")
+ ("next" "D-006C")
("next-file" "N-00839D2F")
("nextafter" "N-035C06D4")
("nf" "N-0267AE6D")
@@ -1378,10 +1378,10 @@
("nldly" "N-03BD477F")
("nlink-t" "N-01153D9E")
("noflsh" "N-0072FF5E")
- ("none" "D-0069")
+ ("none" "D-006B")
("nor" "N-03662D87")
("norf" "N-00C18907")
- ("not" "D-0038")
+ ("not" "D-0039")
("notf" "N-0026CE18")
("nr" "N-03A7AE6D")
("nreconc" "N-012FF2DC")
@@ -1393,7 +1393,7 @@
("nthcdr" "N-03D71D22")
("nthlast" "N-02FC66FA")
("null" "N-03C679D2")
- ("nullify" "D-0075")
+ ("nullify" "D-0077")
("num-str" "N-028043AE")
("numberp" "N-03E9D6E1")
("nzerop" "N-0197FF9D")
@@ -1420,7 +1420,7 @@
("obtain*-block" "N-0102F0EB")
("obtain-block" "N-01C791D0")
("ocrnl" "N-03BD477F")
- ("oddp" "D-0054")
+ ("oddp" "D-0055")
("ofdel" "N-03BD477F")
("off-t" "N-01153D9E")
("offsetof" "N-013D0A5C")
@@ -1452,7 +1452,7 @@
("opthelp-conventions" "N-010286EC")
("opthelp-types" "N-010286EC")
("opts" "N-01D911E8")
- ("or" "D-007D")
+ ("or" "D-007F")
("orec" "N-0003ED2C")
("orf" "N-01E7D2AD")
("ors" "N-02D33A3D")
@@ -1537,7 +1537,7 @@
("pprof" "N-018C92AB")
("pred" "N-038E636C")
("prinl" "N-02FCCE0D")
- ("print" "D-002E")
+ ("print" "D-002F")
("prn" "N-01E7F5F7")
("prod" "N-0163FFE2")
("prof" "N-004C9B10")
@@ -1568,21 +1568,21 @@
("push-after-load" "N-01F489FE")
("pushhash" "N-022660B2")
("pushnew" "N-02C37AB0")
- ("put-buf" "D-0095")
+ ("put-buf" "D-0097")
("put-byte" "D-000D")
("put-carray" "N-00737951")
- ("put-char" "D-0042")
+ ("put-char" "D-0043")
("put-json" "N-009C27EF")
("put-jsonl" "N-009C27EF")
("put-jsons" "N-0124CAE6")
("put-line" "N-012163C3")
("put-lines" "N-0367B282")
("put-obj" "N-025DB229")
- ("put-string" "D-0072")
+ ("put-string" "D-0074")
("put-strings" "N-0367B282")
("pwd" "N-0047F5F6")
("qquote" "N-01665185")
- ("qref" "D-006B")
+ ("qref" "D-006D")
("quantile" "N-0318C018")
("quip" "N-03C6D422")
("quote" "N-0163F998")
@@ -1673,7 +1673,7 @@
("remqual" "N-000ECD82")
("remqual*" "N-00B85CD2")
("rename-path" "N-016EF40C")
- ("rep" "D-005E")
+ ("rep" "D-005F")
("repeat" "D-0018")
("replace" "N-035991E1")
("replace-buf" "N-01C59E4E")
@@ -1683,7 +1683,7 @@
("replace-struct" "N-01A8343B")
("replace-tree-iter" "N-01225FF3")
("replace-vec" "N-01F59E62")
- ("require" "D-003F")
+ ("require" "D-0040")
("res" "N-03D33A57")
("reset-struct" "N-002A609F")
("rest" "N-02288559")
@@ -1697,7 +1697,7 @@
("rfind" "N-0301CDB6")
("rfind-if" "N-0301CDB6")
("right" "N-020D5C1D")
- ("rint" "D-007A")
+ ("rint" "D-007C")
("rlcp" "N-024EB211")
("rlcp-tree" "N-024EB211")
("rlet" "N-008212A0")
@@ -1719,11 +1719,11 @@
("rng-" "N-01A056E4")
("rot" "N-025DB962")
("rotate" "N-0166291D")
- ("round" "D-0074")
+ ("round" "D-0076")
("round-rem" "N-02DE978F")
("round1" "N-03EA1351")
("rperm" "N-0188EBDE")
- ("rplaca" "D-005D")
+ ("rplaca" "D-005E")
("rplacd" "D-0003")
("rpoly" "N-026201AD")
("rpos" "N-01F68300")
@@ -1774,7 +1774,7 @@
("seq-next" "N-02E3D643")
("seq-reset" "N-01CA6912")
("seqp" "N-03C6CAE0")
- ("set" "D-007B")
+ ("set" "D-007D")
("set-cflags" "N-02061924")
("set-hash-userdata" "N-030B40A7")
("set-iflags" "N-02061924")
@@ -1861,11 +1861,11 @@
("sig-winch" "N-0176430F")
("sig-xcpu" "N-0176430F")
("sig-xfsz" "N-0176430F")
- ("sign-extend" "D-0051")
- ("significand" "D-0085")
- ("signum" "D-0046")
- ("sin" "D-0076")
- ("sinh" "D-0068")
+ ("sign-extend" "D-0052")
+ ("significand" "D-0087")
+ ("signum" "D-0047")
+ ("sin" "D-0078")
+ ("sinh" "D-006A")
("sixth" "N-01B0FA33")
("size-t" "N-01B6F219")
("size-vec" "N-01000634")
@@ -1916,7 +1916,7 @@
("sockaddr-un" "N-01DD05D2")
("socklen-t" "N-01153D9E")
("sol-socket" "N-031C01CB")
- ("some" "D-002C")
+ ("some" "D-002D")
("some-false" "N-016BDF48")
("some-true" "N-016BDF48")
("sort" "N-03923640")
@@ -1933,22 +1933,22 @@
("split-str" "N-000386B4")
("split-str-set" "N-0296195B")
("spln" "N-026FC0BD")
- ("sqrt" "D-0081")
- ("square" "D-0052")
+ ("sqrt" "D-0083")
+ ("square" "D-0053")
("ssize-t" "N-01153D9E")
("ssort" "N-03923640")
("sspl" "N-0296195B")
("sssucc" "N-038E636C")
("ssucc" "N-038E636C")
("starts-with" "N-004955D4")
- ("stat" "D-0032")
+ ("stat" "D-0033")
("static-slot" "N-02C47D17")
("static-slot-ensure" "N-02E71F31")
("static-slot-home" "N-01F88B0D")
("static-slot-p" "N-032FD510")
("static-slot-set" "N-0017D1B5")
("stdlib" "N-008E4BC2")
- ("str" "D-0063")
+ ("str" "D-0064")
("str-addr" "N-02E1B78B")
("str-buf" "N-012BF6AD")
("str-d" "N-01736060")
@@ -2036,8 +2036,8 @@
("take" "N-00F6D433")
("take-until" "N-01E42C4C")
("take-while" "N-01E42C4C")
- ("tan" "D-0056")
- ("tanh" "D-0035")
+ ("tan" "D-0057")
+ ("tanh" "D-0036")
("tb" "N-02AB6E53")
("tc" "N-029B6E53")
("tcdrain" "N-01AC4760")
@@ -2069,16 +2069,16 @@
("test-set" "N-036C7E9E")
("test-set-indent-mode" "N-01A1F89C")
("tf" "N-007E0508")
- ("tgamma" "D-0080")
+ ("tgamma" "D-0082")
("third" "N-01B0FA33")
- ("throw" "D-0030")
+ ("throw" "D-0031")
("throwf" "N-015466AD")
- ("time" "D-0053")
+ ("time" "D-0054")
("time-fields-local" "N-00789418")
("time-fields-utc" "N-00789418")
("time-local" "N-001284ED")
("time-nsec" "N-03B6DB3D")
- ("time-parse" "D-0066")
+ ("time-parse" "D-0068")
("time-parse-local" "N-00207C99")
("time-parse-utc" "N-00207C99")
("time-str-local" "N-01711783")
@@ -2095,9 +2095,9 @@
("tnode" "N-0008DDFB")
("tnodep" "N-00D8534F")
("to" "N-00AED1A7")
- ("tofloat" "N-01DBC9D7")
+ ("tofloat" "D-0022")
("tofloatz" "N-03E2D4B8")
- ("toint" "N-01DBC9D7")
+ ("toint" "D-0066")
("tointz" "N-03E2D4B8")
("tojson" "N-017848BD")
("tok" "N-0117F60C")
@@ -2109,7 +2109,7 @@
("touch" "N-0038DD42")
("tprint" "N-0217DE45")
("trace" "N-02833733")
- ("trailer" "D-0061")
+ ("trailer" "D-0062")
("transpose" "N-03AA85AD")
("tree" "N-02F6D50B")
("tree-begin" "N-02887FCA")
@@ -2146,7 +2146,7 @@
("trim-short-suffix" "N-03CAC692")
("trim-str" "N-00E6E63B")
("true" "N-00373D97")
- ("trunc" "D-0090")
+ ("trunc" "D-0092")
("trunc-rem" "N-02DE978F")
("trunc1" "N-02E91F51")
("truncate" "N-0032FBF3")
@@ -2197,7 +2197,7 @@
("unless" "N-017EFAB6")
("unquote" "N-036B313D")
("unsetenv" "N-002E0364")
- ("until" "D-004C")
+ ("until" "D-004D")
("until*" "N-01F7BF0B")
("untrace" "N-02833733")
("unuse-package" "N-024BF63F")
@@ -2272,7 +2272,7 @@
("while-match-case" "N-007220BC")
("while-true-match-case" "N-007220BC")
("whilet" "N-0154DC75")
- ("width" "D-004A")
+ ("width" "D-004B")
("width-check" "N-01A9EA49")
("window-map" "N-015AFD48")
("window-mapdo" "N-015AFD48")
@@ -2303,8 +2303,8 @@
("wstr-d" "N-033B8A6D")
("wstr-s" "N-033B8A6D")
("xcase" "N-0072FF5E")
- ("y0" "D-004E")
- ("y1" "D-0036")
+ ("y0" "D-004F")
+ ("y1" "D-0037")
("yield" "N-02AE5C1E")
("yield-from" "N-01556613")
("yn" "N-035C06D4")
@@ -2312,6 +2312,6 @@
("zarray" "N-017039ED")
("zchar" "N-0008D7DC")
("zero-fill" "N-016D3BB5")
- ("zerop" "D-0088")
+ ("zerop" "D-008A")
("zip" "N-03AA85AD")
("znew" "N-00B1FC38"))))
diff --git a/tests/016/ud-arith.tl b/tests/016/ud-arith.tl
index 35a0cb5f..8a8e50df 100644
--- a/tests/016/ud-arith.tl
+++ b/tests/016/ud-arith.tl
@@ -109,7 +109,9 @@
(:method r-remainder (me arg) ^(remainder ,arg ,me.v))
(:method r-scalb (me arg) ^(scalb ,arg ,me.v))
(:method r-scalbln (me arg) ^(scalbln ,arg ,me.v))
- (:method r-yn (me arg) ^(yn ,arg ,me.v)))
+ (:method r-yn (me arg) ^(yn ,arg ,me.v))
+ (:method tofloat (me) ^(tofloat ,me.v))
+ (:method toint (me) ^(toint ,me.v)))
(defvarl n (new numbase v 1))
@@ -226,5 +228,7 @@
(test (scalb 0 n) (scalb 0 1))
(test (scalbln 0 n) (scalbln 0 1))
(test (yn 0 n) (yn 0 1))
+(test (tofloat n) (tofloat 1))
+(test (toint n) (toint 1))
(test (arithp n) t)
diff --git a/txr.1 b/txr.1
index 6edd9efb..442243d5 100644
--- a/txr.1
+++ b/txr.1
@@ -50128,6 +50128,15 @@ is a floating-point number, then it is converted by
as if by the function
.codn int-flo .
+If
+.meta value
+is a structure, then it is expected to implement the
+.code tofloat
+or
+.code toint
+method. This method is invoked by the same-named function, and the value is
+returned.
+
.coNP Variables @ fixnum-min and @ fixnum-max
.desc
These variables hold, respectively, the most negative value of the
@@ -51556,6 +51565,28 @@ takes place, and its return value is taken as the result
of the operation.
..
+.um tofloat
+
+The method should return a floating-point value.
+It is also permissible for the method to return
+.codn nil ,
+in which case if it is invoked via
+.codn tofloatz ,
+that function will replace the
+.code nil
+return with value of 0.0.
+
+.um toint
+
+The method should return an integer value.
+It is permissible for the method to return
+.codn nil ,
+in which case if it is invoked via
+.codn tointz ,
+that function will replace the
+.code nil
+return with value of 0.
+
.bmcv +
.bmnl -
.bmnr -- -