diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-01-24 22:48:37 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-01-24 22:48:37 -0800 |
commit | 8195fbed4a8067362656d38e56fec3c4eb3deef1 (patch) | |
tree | 4de31eaa6b74ec1a97a8c767a3d7b7d8e587b409 | |
parent | 8e785a1f47e49a411abadc8b690b175ff0e231e6 (diff) | |
download | txr-8195fbed4a8067362656d38e56fec3c4eb3deef1.tar.gz txr-8195fbed4a8067362656d38e56fec3c4eb3deef1.tar.bz2 txr-8195fbed4a8067362656d38e56fec3c4eb3deef1.zip |
lib: revise wording of integer range errors.
* arith.c (c_unum): Fix misleading error message, and instead
specify the range that was violated.
* lib.c (c_num): Similar change: don't refer to a 'cnum range'
which means nothing to the user.
-rw-r--r-- | arith.c | 3 | ||||
-rw-r--r-- | lib.c | 15 |
2 files changed, 10 insertions, 8 deletions
@@ -213,7 +213,8 @@ ucnum c_unum(val num) } /* fallthrough */ range: - uw_throwf(error_s, lit("~s given, non-negative expected"), num, nao); + uw_throwf(error_s, lit("~s is out of allowed range [0, ~a]"), + num, unum(UINT_PTR_MAX), nao); default: type_mismatch(lit("~s is not an integer"), num, nao); } @@ -3099,20 +3099,21 @@ val num(cnum n) return bignum(n); } -cnum c_num(val num) +cnum c_num(val n) { - switch (type(num)) { + switch (type(n)) { case CHR: case NUM: - return coerce(cnum, num) >> TAG_SHIFT; + return coerce(cnum, n) >> TAG_SHIFT; case BGNUM: - if (in_int_ptr_range(num)) { + if (in_int_ptr_range(n)) { int_ptr_t out; - mp_get_intptr(mp(num), &out); + mp_get_intptr(mp(n), &out); return out; } - uw_throwf(error_s, lit("~s is out of cnum range"), num, nao); + uw_throwf(error_s, lit("~s is out of allowed range [~s, ~s]"), + n, num(INT_PTR_MIN), num(INT_PTR_MAX), nao); default: - type_mismatch(lit("~s is not an integer"), num, nao); + type_mismatch(lit("~s is not an integer"), n, nao); } } |