Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bc6b5efff855
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 00e46abf7c37
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 7, 2021

  1. Copy the full SHA
    2ce735c View commit details
  2. Merge pull request #3053 from eggrobin/constexpr-overflow

    Oveflow in constexpr arithmetic with clang 8, continued
    eggrobin authored Jul 7, 2021
    Copy the full SHA
    00e46ab View commit details
Showing with 19 additions and 7 deletions.
  1. +10 −6 base/macros.hpp
  2. +9 −1 numerics/next_body.hpp
16 changes: 10 additions & 6 deletions base/macros.hpp
Original file line number Diff line number Diff line change
@@ -162,13 +162,17 @@ inline void noreturn() { std::exit(0); }
#define CONSTEXPR_CHECK(condition) CHECK(condition)
#define CONSTEXPR_DCHECK(condition) DCHECK(condition)

// Clang for some reason doesn't like FP arithmetic that yields infinities in
// constexpr code (MSVC and GCC are fine with that). This will be fixed in
// Clang 9.0.0, all hail zygoloid.
#if PRINCIPIA_COMPILER_CLANG || PRINCIPIA_COMPILER_CLANG_CL
# define CONSTEXPR_INFINITY const
#else
// Clang for some reason doesn't like FP arithmetic that yields infinities by
// overflow (as opposed to division by zero, which the standard explicitly
// prohibits) in constexpr code (MSVC and GCC are fine with that). This will be
// fixed in Clang 9.0.0, all hail zygoloid.
#define PRINCIPIA_MAY_SIGNAL_OVERFLOW_IN_CONSTEXPR_ARITHMETIC \
!((PRINCIPIA_COMPILER_CLANG || PRINCIPIA_COMPILER_CLANG_CL) && \
__clang_major__ >= 9)
#if PRINCIPIA_MAY_SIGNAL_OVERFLOW_IN_CONSTEXPR_ARITHMETIC
# define CONSTEXPR_INFINITY constexpr
#else
# define CONSTEXPR_INFINITY const
#endif

#if PRINCIPIA_COMPILER_MSVC
10 changes: 9 additions & 1 deletion numerics/next_body.hpp
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ constexpr SourceFormat NextUp(SourceFormat const x) {
return std::numeric_limits<SourceFormat>::denorm_min();
}
if (x == std::numeric_limits<SourceFormat>::infinity()) {
// TODO(egg): Should we be signalling the overflow exception?
return std::numeric_limits<SourceFormat>::infinity();
}
if (x == -std::numeric_limits<SourceFormat>::infinity()) {
@@ -50,6 +49,15 @@ constexpr SourceFormat NextUp(SourceFormat const x) {
if (signed_significand == -1) {
return x + ulp / std::numeric_limits<SourceFormat>::radix;
}
#if !PRINCIPIA_MAY_SIGNAL_OVERFLOW_IN_CONSTEXPR_ARITHMETIC
// When |x| is the largest finite number in |SourceFormat|, the operation
// |x + ulp| below results in positive infinity and signals the overflow
// exception. On compilers that think overflow is non-constexpr, explicitly
// return an infinity.
if (x == -std::numeric_limits<SourceFormat>::max()) {
return std::numeric_limits<SourceFormat>::infinity();
}
#endif
return x + ulp;
}