-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix digits10 bug #4281
Fix digits10 bug #4281
Conversation
Co-Authored-By: Chris Marsh <chrismarsh.c2@gmail.com> Co-Authored-By: Daniel Arndt <arndtd@ornl.gov>
c8beb93
to
bb72d32
Compare
(I permuted the two commits so that both will compile so it is not annoying when doing git bisections) |
This didn't pass. Maybe really just hardcoding those values is the way to go. |
What about diff --git a/core/src/Kokkos_NumericTraits.hpp b/core/src/Kokkos_NumericTraits.hpp
index a0b96b8cb..1b0460370 100644
--- a/core/src/Kokkos_NumericTraits.hpp
+++ b/core/src/Kokkos_NumericTraits.hpp
@@ -166,9 +166,29 @@ template <class> struct max_digits10_helper {};
//template <> struct max_digits10_helper<float> { static constexpr int value = FLT_DECIMAL_DIG; };
//template <> struct max_digits10_helper<double> { static constexpr int value = DBL_DECIMAL_DIG; };
//template <> struct max_digits10_helper<long double> { static constexpr int value = LDBL_DECIMAL_DIG; };
-template <> struct max_digits10_helper<float> { static constexpr int value = 9; };
-template <> struct max_digits10_helper<double> { static constexpr int value = 17; };
-template <> struct max_digits10_helper<long double> { static constexpr int value = 21; };
+template <> struct max_digits10_helper<float> {
+#ifdef FLT_DECIMAL_DIG
+ static constexpr int value = FLT_DECIMAL_DIG;
+#else
+ static constexpr int value = (digits_helper<float>::value * 643L+2135)/2136+1;
+#endif
+};
+template <> struct max_digits10_helper<double> {
+#ifdef DBL_DECIMAL_DIG
+ static constexpr int value = DBL_DECIMAL_DIG;
+#else
+ static constexpr int value = (digits_helper<double>::value * 643L+2135)/2136+1;
+#endif
+};
+template <> struct max_digits10_helper<long double> {
+#ifdef DECIMAL_DIG
+ static constexpr int value = DECIMAL_DIG;
+#elif defined(LDBL_DECIMAL_DIG)
+ static constexpr int value = LDBL_DECIMAL_DIG;
+#else
+ static constexpr int value = (digits_helper<long double>::value * 643L+2135)/2136+1;
+#endif
+}; (untested) for trying to fix the failing tests? |
380b55a
to
8addcda
Compare
Discovered issue with long double specialization. Replaced hardcoded values by formula suggested by cppreference.com ``` std::ceil(std::numeric_limits<T>::digits * std::log10(2) + 1) ``` Co-Authored-By: Daniel Arndt <arndtd@ornl.gov>
8addcda
to
2a12ea7
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK to me.
* Fixes constexpr errors with frounding-math on gcc < 10. Use std::numeric_limits digits10 instead of bespoke version trilinos/Trilinos/issues/9056 /issues/4267 * Remove limits + std::numeric_limits as this is not available on all backends and follow gcc's constexpr-valid approximation of log10(2) * Update the log10_2 type to int * Revert log10_2 changes en lieu of /pull/4281 * declare const Co-authored-by: Damien L-G <dalg24+github@gmail.com> * update comment * remove const as it causes various ctors to be implicitly deleted Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Fix #4280
Conflicts with #4278