diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-04 16:16:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-04 16:16:28 +0100 |
commit | 1377e23afff90128b18ac60c10071295fc0afbab (patch) | |
tree | 04397dab9be96a5978e08366299671a8aa507267 /include | |
parent | 8907ce41a36f8d42097d884550fb3cfbba62e6c5 (diff) | |
parent | b605dbfcf04f310e08634b52507da7a4155bfce1 (diff) |
Merge pull request #30 from jow-/rework-number-handling
treewide: rework numeric value handling
Diffstat (limited to 'include')
-rw-r--r-- | include/ucode/types.h | 32 | ||||
-rw-r--r-- | include/ucode/vallist.h | 2 |
2 files changed, 29 insertions, 5 deletions
diff --git a/include/ucode/types.h b/include/ucode/types.h index 49d910b..cbd03dd 100644 --- a/include/ucode/types.h +++ b/include/ucode/types.h @@ -372,24 +372,46 @@ void ucv_to_stringbuf_formatted(uc_vm_t *, uc_stringbuf_t *, uc_value_t *, size_ uc_type_t ucv_cast_number(uc_value_t *, int64_t *, double *); +uc_value_t *ucv_to_number(uc_value_t *); + static inline double ucv_to_double(uc_value_t *v) { - int64_t n; + uc_value_t *nv; double d; - return (ucv_cast_number(v, &n, &d) == UC_DOUBLE) ? d : (double)n; + nv = ucv_to_number(v); + d = ucv_double_get(nv); + ucv_put(nv); + + return d; } static inline int64_t ucv_to_integer(uc_value_t *v) { + uc_value_t *nv; int64_t n; - double d; - return (ucv_cast_number(v, &n, &d) == UC_DOUBLE) ? (int64_t)d : n; + nv = ucv_to_number(v); + n = ucv_int64_get(nv); + ucv_put(nv); + + return n; } +static inline uint64_t +ucv_to_unsigned(uc_value_t *v) +{ + uc_value_t *nv; + uint64_t u; + + nv = ucv_to_number(v); + u = ucv_uint64_get(nv); + ucv_put(nv); + + return u; +} static inline bool ucv_is_callable(uc_value_t *uv) @@ -437,7 +459,7 @@ ucv_is_scalar(uc_value_t *uv) bool ucv_is_equal(uc_value_t *, uc_value_t *); bool ucv_is_truish(uc_value_t *); -bool ucv_compare(int, uc_value_t *, uc_value_t *); +bool ucv_compare(int, uc_value_t *, uc_value_t *, int *); uc_value_t *ucv_key_get(uc_vm_t *, uc_value_t *, uc_value_t *); uc_value_t *ucv_key_set(uc_vm_t *, uc_value_t *, uc_value_t *, uc_value_t *); diff --git a/include/ucode/vallist.h b/include/ucode/vallist.h index a3d94e8..47ddc7d 100644 --- a/include/ucode/vallist.h +++ b/include/ucode/vallist.h @@ -41,6 +41,8 @@ typedef enum { TAG_PTR = 6 } uc_value_type_t; +uc_value_t *uc_number_parse(const char *buf, char **end); + void uc_vallist_init(uc_value_list_t *list); void uc_vallist_free(uc_value_list_t *list); |