10#ifndef FDL_ROUNDING_INTERNAL_H
11#define FDL_ROUNDING_INTERNAL_H
19namespace fdl::detail {
32 constexpr auto kMax =
static_cast<double>(std::numeric_limits<int64_t>::max());
33 constexpr auto kMin =
static_cast<double>(std::numeric_limits<int64_t>::min());
35 return std::numeric_limits<int64_t>::max();
38 return std::numeric_limits<int64_t>::min();
40 return static_cast<int64_t
>(value);
53 double rounded = std::round(value);
55 double const remainder = value - std::floor(value);
56 if (std::abs(remainder - constants::kHalfway) < constants::kFpHalfwayTolerance) {
59 if (r % constants::kEvenDivisor != 0) {
61 rounded = std::floor(value + constants::kHalfway);
63 rounded = std::ceil(value - constants::kHalfway);
Named constants replacing magic numbers throughout the FDL core library.
int64_t safe_to_int64(double value)
Safely cast a double to int64_t, clamping to [INT64_MIN, INT64_MAX].
Definition fdl_rounding.h:30
int64_t bankers_round(double value)
Banker's rounding (half-to-even), matching Python's built-in round().
Definition fdl_rounding.h:52