FDL Core Library
ASC Framing Decision List — C/C++ Reference Implementation
Loading...
Searching...
No Matches
Functions
fdl_rounding.h File Reference

Banker's rounding (half-to-even) implementation. More...

#include <cmath>
#include <cstdint>
#include <limits>
#include "fdl_constants.h"

Go to the source code of this file.

Functions

int64_t fdl::detail::safe_to_int64 (double value)
 Safely cast a double to int64_t, clamping to [INT64_MIN, INT64_MAX].
 
int64_t fdl::detail::bankers_round (double value)
 Banker's rounding (half-to-even), matching Python's built-in round().
 

Detailed Description

Banker's rounding (half-to-even) implementation.

Provides the core rounding primitive that matches Python's built-in round() behavior, ensuring consistent results across the C++ and Python implementations.

Function Documentation

◆ safe_to_int64()

int64_t fdl::detail::safe_to_int64 ( double  value)
inline

Safely cast a double to int64_t, clamping to [INT64_MIN, INT64_MAX].

Prevents undefined behavior from casting doubles that exceed the representable range of int64_t.

Parameters
valueThe floating-point value to convert.
Returns
The integer value, clamped to int64_t bounds.

◆ bankers_round()

int64_t fdl::detail::bankers_round ( double  value)
inline

Banker's rounding (half-to-even), matching Python's built-in round().

At exact halfway points (e.g. 0.5, 1.5), rounds to the nearest even integer. This avoids systematic rounding bias.

Parameters
valueThe floating-point value to round.
Returns
Rounded integer value.