diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-11-29 10:29:49 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-11-29 10:37:57 +0100 |
commit | 83661021edbeeeef56d5687b44619e557e09e568 (patch) | |
tree | 9a7b859b208acc5bfbb40f2c4a791835b519439c | |
parent | eef83d3e849743911b29133e6ef873f7e0d34c1c (diff) |
math: add isnan() function
Add a new `isnan()` convenience function to the math library which can
be used to test if a given value is a NaN double.
The same test can be realized without the math library by using a function
similar to the following one:
function isNaN(x) {
return x != x;
}
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | lib/math.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -169,6 +169,14 @@ uc_srand(uc_vm_t *vm, size_t nargs) return NULL; } +static uc_value_t * +uc_isnan(uc_vm_t *vm, size_t nargs) +{ + uc_value_t *v = uc_fn_arg(0); + + return ucv_boolean_new(ucv_type(v) == UC_DOUBLE && isnan(ucv_double_get(v))); +} + static const uc_function_list_t math_fns[] = { { "abs", uc_abs }, { "atan2", uc_atan2 }, @@ -180,6 +188,7 @@ static const uc_function_list_t math_fns[] = { { "pow", uc_pow }, { "rand", uc_rand }, { "srand", uc_srand }, + { "isnan", uc_isnan }, }; void uc_module_init(uc_vm_t *vm, uc_value_t *scope) |