]> git.kaiwu.me - njs.git/commitdiff
Ensuring that double type is always evaluated at standard precision.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 6 Jul 2022 05:58:12 +0000 (22:58 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 6 Jul 2022 05:58:12 +0000 (22:58 -0700)
Previously, GCC on x86 uses extended precision for intermediate
calculations by default.  This might conflict with njs_diyfp_t because
GCC is not always rounds back the intermediate values to standard
precision.

The fix is to explicitly tell to a compiler to do so.

This closes #507 issue on Github.

auto/types

index 7bb9c16ad362d337d5870fb8197b66a7cfcc2d19..6e1c2c61af6f1ff54017f13c63ccd5da2d46ecc6 100644 (file)
@@ -118,3 +118,57 @@ njs_feature_test="#include <time.h>
                       return 0;
                   }"
 . auto/feature
+
+
+# Ensuring that double type is always evaluated at standard
+# precision required by njs_diyfp_t
+
+
+case $NJS_CC_NAME in
+
+    gcc)
+        NJS_CFLAGS="$NJS_CFLAGS -fexcess-precision=standard"
+    ;;
+
+    clang)
+
+        njs_found=no
+
+        njs_feature="flag -ffp-eval-method=double"
+        njs_feature_name=NJS_HAVE_FP_EVAL_METHOD
+        njs_feature_run=no
+        njs_feature_incs="-ffp-eval-method=double"
+        njs_feature_libs=
+        njs_feature_test="int main(void) {
+                             return 0;
+                         }"
+
+        . auto/feature
+
+        if [ $njs_found = yes ]; then
+            NJS_CFLAGS="$NJS_CFLAGS -ffp-eval-method=double"
+        fi
+
+    ;;
+
+    SunC)
+
+        njs_found=no
+
+        njs_feature="flag -xarch=sse2"
+        njs_feature_name=NJS_HAVE_XARCH_SSE2
+        njs_feature_run=no
+        njs_feature_incs="-xarch=sse2"
+        njs_feature_libs=
+        njs_feature_test="int main(void) {
+                             return 0;
+                         }"
+
+        . auto/feature
+
+        if [ $njs_found = yes ]; then
+            NJS_CFLAGS="$NJS_CFLAGS -xarch=sse2"
+        fi
+    ;;
+
+esac