]> git.kaiwu.me - njs.git/commitdiff
Fixed conversion of NAN and INF to uint32_t on some platforms.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 29 Nov 2018 15:14:12 +0000 (18:14 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 29 Nov 2018 15:14:12 +0000 (18:14 +0300)
njs/njs_builtin.c
njs/njs_number.c
nxt/auto/clang

index 08dab6a51d267cb907f526169181180744bfd25e..2b3ee097071153fb51fcc51bdfbd146723e903f0 100644 (file)
@@ -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) {
index ea28e2dc476ba16a5506eed7ac3de3b4a1ef5698..6c3a066ec2836ddced0137cc99afd8519ad02dfc 100644 (file)
@@ -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
index 45dd8c49801b2cf2658f499e6f173f76d909744d..b79abef4e11bb3c7d7a9de783f945f95ec1f339d 100644 (file)
@@ -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 <math.h>
+                  #include <stdio.h>
+                  #include <stdint.h>
+
+                  int main(void) {
+                      int64_t  i64 = sqrt(-1);
+                      printf(\"%x\", (uint32_t) i64);
+                      return 0;
+                  }"
+. ${NXT_AUTO}feature