summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-06-01 13:08:36 +0200
committerGitHub <noreply@github.com>2022-06-01 13:08:36 +0200
commitb211ca0e420d8086d3fa0358413a6f8b44df1115 (patch)
tree2e60555dc4ce9e81b42b7556dd2e2491473f776c /lib.c
parent9b35df7b37f21043f4be0bdba011000ad4f7cf0f (diff)
parentd99604749d658f5f344d53e77dd52fbb0f6d176c (diff)
Merge pull request #78 from jow-/number-literals
Number literals
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 6793972..4d37531 100644
--- a/lib.c
+++ b/lib.c
@@ -570,7 +570,22 @@ uc_hex(uc_vm_t *vm, size_t nargs)
static uc_value_t *
uc_int(uc_vm_t *vm, size_t nargs)
{
- int64_t n = ucv_to_integer(uc_fn_arg(0));
+ uc_value_t *val = uc_fn_arg(0);
+ uc_value_t *base = uc_fn_arg(1);
+ char *e, *v;
+ int64_t n;
+
+ if (ucv_type(val) == UC_STRING) {
+ errno = 0;
+ v = ucv_string_get(val);
+ n = strtoll(v, &e, base ? ucv_int64_get(base) : 10);
+
+ if (e == v)
+ return ucv_double_new(NAN);
+ }
+ else {
+ n = ucv_to_integer(val);
+ }
if (errno == EINVAL || errno == ERANGE)
return ucv_double_new(NAN);