-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6199c6
commit ed05fb6
Showing
10 changed files
with
180 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2024 Tobias Hienzsch | ||
|
||
#pragma once | ||
|
||
#include <limits> | ||
|
||
#if (defined(__APPLE__) or defined(__clang__)) and not defined(__INTEL_LLVM_COMPILER) | ||
#define PFFDTD_HAS_FLOAT16 | ||
#endif | ||
|
||
namespace pffdtd { | ||
|
||
template<typename T> | ||
struct FloatTraits; | ||
|
||
#if defined(PFFDTD_HAS_FLOAT16) | ||
template<> | ||
struct FloatTraits<_Float16> { | ||
static constexpr auto digits = 11; | ||
static constexpr auto minExponent = -13; | ||
static constexpr auto maxExponent = 16; | ||
}; | ||
#endif | ||
|
||
template<> | ||
struct FloatTraits<float> { | ||
static constexpr auto digits = std::numeric_limits<float>::digits; | ||
static constexpr auto minExponent = std::numeric_limits<float>::min_exponent; | ||
static constexpr auto maxExponent = std::numeric_limits<float>::max_exponent; | ||
}; | ||
|
||
template<> | ||
struct FloatTraits<double> { | ||
static constexpr auto digits = std::numeric_limits<double>::digits; | ||
static constexpr auto minExponent = std::numeric_limits<double>::min_exponent; | ||
static constexpr auto maxExponent = std::numeric_limits<double>::max_exponent; | ||
}; | ||
|
||
} // namespace pffdtd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2024 Tobias Hienzsch | ||
|
||
#include "precision.hpp" | ||
|
||
#include "pffdtd/exception.hpp" | ||
#include "pffdtd/float.hpp" | ||
|
||
namespace pffdtd { | ||
|
||
template<typename T> | ||
constexpr auto EPS = 0.0; | ||
|
||
template<> | ||
constexpr auto EPS<float> = 1.19209289e-07; | ||
|
||
auto getEpsilon(Precision precision) -> double { | ||
switch (precision) { | ||
case Precision::Half: return EPS<float>; | ||
case Precision::Float: return EPS<float>; | ||
case Precision::Double: return EPS<double>; | ||
|
||
case Precision::DoubleHalf: return EPS<float>; | ||
case Precision::DoubleFloat: return EPS<float>; | ||
case Precision::DoubleDouble: return EPS<double>; | ||
|
||
default: break; | ||
} | ||
|
||
raisef<std::invalid_argument>("invalid precision = {}", int(precision)); | ||
} | ||
|
||
auto getMinMaxExponent(Precision precision) -> std::pair<int, int> { | ||
using std::pair; | ||
switch (precision) { | ||
case Precision::Float: return pair{FloatTraits<float>::minExponent, FloatTraits<float>::maxExponent}; | ||
case Precision::DoubleFloat: return pair{FloatTraits<float>::minExponent, FloatTraits<float>::maxExponent}; | ||
|
||
case Precision::Double: return pair{FloatTraits<double>::minExponent, FloatTraits<double>::maxExponent}; | ||
case Precision::DoubleDouble: return pair{FloatTraits<double>::minExponent, FloatTraits<double>::maxExponent}; | ||
|
||
#if defined(PFFDTD_HAS_FLOAT16) | ||
case Precision::Half: return pair{FloatTraits<_Float16>::minExponent, FloatTraits<_Float16>::maxExponent}; | ||
case Precision::DoubleHalf: return pair{FloatTraits<_Float16>::minExponent, FloatTraits<_Float16>::maxExponent}; | ||
#endif | ||
|
||
default: break; | ||
} | ||
|
||
raisef<std::invalid_argument>("invalid precision = {}", int(precision)); | ||
} | ||
|
||
} // namespace pffdtd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.