quokka
quokka copied to clipboard
copy Kokkos implementation of min/max/clamp
Describe the proposal
Different C++ standard library implementations implement std::min
, std::max
and std::clamp
in incompatible ways. We can avoid this by implementing these functions ourselves, e.g. by copying the implementation from Kokkos:
https://github.com/kokkos/kokkos/blob/master/core/src/Kokkos_MinMaxClamp.hpp
Describe alternatives you've considered
We could use the amrex::min
and amrex::max
implementation, but those actually call the C++ standard library implementation: https://github.com/AMReX-Codes/amrex/blob/3fe7aadc23c94a038b306af54ff732ce5564c3d1/Src/Base/AMReX_Algorithm.H#L23, which leaves us with the same problem as before.
Additional context There are weird numerical edge cases with comparisons with different compilers and different C++ standard libraries with comparisons of NaN, inf, and denormals.