WPILibC++ 2024.3.2
safe_duration_cast Namespace Reference

Functions

template<typename To , typename From , FMT_ENABLE_IF(!std::is_same< From, To >::value && std::numeric_limits< From >::is_signed== std::numeric_limits< To >::is_signed) >
FMT_CONSTEXPR To lossless_integral_conversion (const From from, int &ec)
 converts From to To, without loss. More...
 
template<typename To , typename From , FMT_ENABLE_IF(!std::is_same< From, To >::value) >
FMT_CONSTEXPR To safe_float_conversion (const From from, int &ec)
 converts From to To if possible, otherwise ec is set. More...
 
template<typename To , typename FromRep , typename FromPeriod , FMT_ENABLE_IF(std::is_integral< FromRep >::value) , FMT_ENABLE_IF(std::is_integral< typename To::rep >::value) >
To safe_duration_cast (std::chrono::duration< FromRep, FromPeriod > from, int &ec)
 safe duration cast between integral durations More...
 

Function Documentation

◆ lossless_integral_conversion()

template<typename To , typename From , FMT_ENABLE_IF(!std::is_same< From, To >::value && std::numeric_limits< From >::is_signed== std::numeric_limits< To >::is_signed) >
FMT_CONSTEXPR To safe_duration_cast::lossless_integral_conversion ( const From  from,
int &  ec 
)

converts From to To, without loss.

If the dynamic value of from can't be converted to To without loss, ec is set.

◆ safe_duration_cast()

template<typename To , typename FromRep , typename FromPeriod , FMT_ENABLE_IF(std::is_integral< FromRep >::value) , FMT_ENABLE_IF(std::is_integral< typename To::rep >::value) >
To safe_duration_cast::safe_duration_cast ( std::chrono::duration< FromRep, FromPeriod >  from,
int &  ec 
)

safe duration cast between integral durations

safe duration_cast between floating point durations

◆ safe_float_conversion()

template<typename To , typename From , FMT_ENABLE_IF(!std::is_same< From, To >::value) >
FMT_CONSTEXPR To safe_duration_cast::safe_float_conversion ( const From  from,
int &  ec 
)

converts From to To if possible, otherwise ec is set.

input output
NaN NaN
Inf Inf
normal, fits in output converted (possibly lossy)
normal, does not fit in output ec is set
subnormal best effort
-Inf -Inf