From: Dmitry Volyntsev Date: Thu, 29 Nov 2018 15:14:12 +0000 (+0300) Subject: Fixed conversion of NAN and INF to uint32_t on some platforms. X-Git-Tag: 0.2.7~17 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=29dd2535ab8a59a713f6d6f1210145b5ee93bb90;p=njs.git Fixed conversion of NAN and INF to uint32_t on some platforms. --- diff --git a/njs/njs_builtin.c b/njs/njs_builtin.c index 08dab6a5..2b3ee097 100644 --- a/njs/njs_builtin.c +++ b/njs/njs_builtin.c @@ -1085,7 +1085,7 @@ njs_dump_value(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, value = njs_arg(args, nargs, 1); indent = njs_arg(args, nargs, 2); - n = indent->data.u.number; + n = njs_primitive_value_to_integer(indent); n = nxt_min(n, 5); if (njs_vm_value_dump(vm, &str, value, n) != NXT_OK) { diff --git a/njs/njs_number.c b/njs/njs_number.c index ea28e2dc..6c3a066e 100644 --- a/njs/njs_number.c +++ b/njs/njs_number.c @@ -789,6 +789,17 @@ njs_number_to_integer(double num) { int64_t i64; +#if (NXT_NAN_TO_UINT_CONVERSION != 0) + /* + * PPC32: NaN and Inf are converted to 0x8000000080000000 + * and become non-zero after truncation. + */ + + if (isnan(num) || isinf(num)) { + return 0; + } +#endif + /* * ES5.1: integer must be modulo 2^32. * 2^53 is the largest integer number which can be stored safely diff --git a/nxt/auto/clang b/nxt/auto/clang index 45dd8c49..b79abef4 100644 --- a/nxt/auto/clang +++ b/nxt/auto/clang @@ -302,3 +302,20 @@ else . ${NXT_AUTO}feature fi + + +nxt_feature="NAN to uint conversion" +nxt_feature_name=NXT_NAN_TO_UINT_CONVERSION +nxt_feature_run=value +nxt_feature_incs= +nxt_feature_libs=-lm +nxt_feature_test="#include + #include + #include + + int main(void) { + int64_t i64 = sqrt(-1); + printf(\"%x\", (uint32_t) i64); + return 0; + }" +. ${NXT_AUTO}feature