I'm using std::round from cmath header file. I want the __round intrinsic function to be used, but I could not find any function supporting just double parameter, there is only long double version which casts the parameter to double anyways.
_NODISCARD _Check_return_ inline long double round(_In_ long double _Xx) noexcept /* strengthened */ {
#if _HAS_CMATH_INTRINSICS
return __round(static_cast<double>(_Xx));
#elif defined(__clang__)
return __builtin_roundl(_Xx);
#else // ^^^ defined(__clang__) / intrinsics unavailable vvv
return _CSTD roundl(_Xx);
#endif // ^^^ intrinsics unavailable ^^^
}
To use the version with __round intrinsic function I have to cast the parameter to long double otherwise the old C version from math.h (corecrt_math.h) header file is used, which is much slower.
Is there any reason for that or am I doing anything wrong?
const double number{ -0.493 };
const auto result{ std::round(number) }; // uses C function from math.h
const auto result{ std::round(static_cast<long double>(number)) }; // uses std::round from cmath with __round intrinsic function
I found this issue Use ceil/floor/round/etc. intrinsics so I don't know if this is still in progress, but it's been 4 years since the issue was opened..
I'm using
std::roundfrom cmath header file. I want the__roundintrinsic function to be used, but I could not find any function supporting justdoubleparameter, there is onlylong doubleversion which casts the parameter todoubleanyways.To use the version with
__roundintrinsic function I have to cast the parameter tolong doubleotherwise the old C version from math.h (corecrt_math.h) header file is used, which is much slower.Is there any reason for that or am I doing anything wrong?
I found this issue Use ceil/floor/round/etc. intrinsics so I don't know if this is still in progress, but it's been 4 years since the issue was opened..