std::numeric_limits<T>::round_error - cppreference.com

From cppreference.com

staticTround_error()throw();(until C++11)staticconstexprTround_error()noexcept;(since C++11)Returns the largest possible rounding error in ULPs (

units in the last place

) as defined by ISO 10967, which can vary from 0.5 (rounding to the nearest digit) to 1.0 (rounding to zero or to infinity). It is only meaningful if std::numeric_limits<T>::is_integer==false.

Return value

Tstd::numeric_limits<T>::round_error()/* non-specialized */T()boolfalsechar0signedchar0unsignedchar0wchar_t0char8_t(since C++20)0char16_t(since C++11)0char32_t(since C++11)0short0unsignedshort0int0unsignedint0long0unsignedlong0longlong(since C++11)0unsignedlonglong(since C++11)0float0.5Fdouble0.5longdouble0.5LExample

Run this code

#include<limits>#include<meta>#include<print>intmain(){std::println("The largest possible rounding error in ULPs:");templatefor(constexprautotype:{^^bool,^^float,^^double,^^longdouble}){usingT=typename[:type:];ifconstexpr(std::numeric_limits<T>::is_integer)continue;constexprstaticautoname=std::define_static_string(std::meta::display_string_of(type));std::println("“{}” : {}",name,std::numeric_limits<T>::round_error());}}Output:

The largest possible rounding error in ULPs: “float” : 0.5 “double” : 0.5 “long double” : 0.5 See also

[static]

identifies the rounding style used by the type
(public static member constant)

[edit]