Skip to content
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

Merged
merged 4 commits into from
Sep 1, 2021
Merged

Fix digits10 bug #4281

merged 4 commits into from
Sep 1, 2021

Conversation

dalg24
Copy link
Member

@dalg24 dalg24 commented Sep 1, 2021

Fix #4280
Conflicts with #4278

dalg24 and others added 2 commits September 1, 2021 08:02
Co-Authored-By: Chris Marsh <chrismarsh.c2@gmail.com>
Co-Authored-By: Daniel Arndt <arndtd@ornl.gov>
@dalg24
Copy link
Member Author

dalg24 commented Sep 1, 2021

(I permuted the two commits so that both will compile so it is not annoying when doing git bisections)

@crtrott
Copy link
Member

crtrott commented Sep 1, 2021

This didn't pass. Maybe really just hardcoding those values is the way to go.

@masterleinad
Copy link
Contributor

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?

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>
@dalg24
Copy link
Member Author

dalg24 commented Sep 1, 2021

CUDA-9.2-NVCC failure is clearly unrelated

@crtrott crtrott added the Blocks Promotion Overview issue for release-blocking bugs label Sep 1, 2021
Copy link
Contributor

@masterleinad masterleinad left a 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.

@crtrott crtrott merged commit 5c921c1 into kokkos:develop Sep 1, 2021
@dalg24 dalg24 deleted the fix_digits10_bug branch September 1, 2021 20:11
crtrott pushed a commit that referenced this pull request Sep 2, 2021
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocks Promotion Overview issue for release-blocking bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants