diff --git a/stl/inc/cmath b/stl/inc/cmath index 6137ec53fa4..cf07a5b9424 100644 --- a/stl/inc/cmath +++ b/stl/inc/cmath @@ -19,14 +19,6 @@ _STL_DISABLE_CLANG_WARNINGS #pragma push_macro("new") #undef new -_NODISCARD _Check_return_ inline double pow(_In_ double _Xx, _In_ int _Yx) noexcept /* strengthened */ { - if (_Yx == 2) { - return _Xx * _Xx; - } - - return _CSTD pow(_Xx, static_cast(_Yx)); -} - _NODISCARD _Check_return_ inline float acos(_In_ float _Xx) noexcept /* strengthened */ { return _CSTD acosf(_Xx); } @@ -199,14 +191,6 @@ _NODISCARD _Check_return_ inline float pow(_In_ float _Xx, _In_ float _Yx) noexc return _CSTD powf(_Xx, _Yx); } -_NODISCARD _Check_return_ inline float pow(_In_ float _Xx, _In_ int _Yx) noexcept /* strengthened */ { - if (_Yx == 2) { - return _Xx * _Xx; - } - - return _CSTD powf(_Xx, static_cast(_Yx)); -} - _NODISCARD _Check_return_ inline float remainder(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ { return _CSTD remainderf(_Xx, _Yx); } @@ -442,14 +426,6 @@ _NODISCARD _Check_return_ inline long double pow(_In_ long double _Xx, _In_ long return _CSTD powl(_Xx, _Yx); } -_NODISCARD _Check_return_ inline long double pow(_In_ long double _Xx, _In_ int _Yx) noexcept /* strengthened */ { - if (_Yx == 2) { - return _Xx * _Xx; - } - - return _CSTD powl(_Xx, static_cast(_Yx)); -} - _NODISCARD _Check_return_ inline long double remainder(_In_ long double _Xx, _In_ long double _Yx) noexcept /* strengthened */ { return _CSTD remainderl(_Xx, _Yx); @@ -517,13 +493,6 @@ double frexp(_Ty _Value, _Out_ int* const _Exp) noexcept /* strengthened */ { return _CSTD frexp(static_cast(_Value), _Exp); } -// FUNCTION TEMPLATE pow -template && _STD is_arithmetic_v<_Ty2>, int> = 0> -_NODISCARD _STD _Common_float_type_t<_Ty1, _Ty2> pow(const _Ty1 _Left, const _Ty2 _Right) noexcept /* strengthened */ { - using _Common = _STD _Common_float_type_t<_Ty1, _Ty2>; - return _CSTD pow(static_cast<_Common>(_Left), static_cast<_Common>(_Right)); -} - // FUNCTION TEMPLATE fma #if !_HAS_IF_CONSTEXPR inline float _Fma(float _Left, float _Middle, float _Right) noexcept { @@ -643,7 +612,7 @@ _GENERIC_MATH1(cbrt) _GENERIC_MATH1(fabs) _GENERIC_MATH2(hypot) // 3-arg hypot() is hand-crafted -// pow() is hand-crafted +_GENERIC_MATH2(pow) _GENERIC_MATH1(sqrt) _GENERIC_MATH1(erf) _GENERIC_MATH1(erfc) diff --git a/tests/std/test.lst b/tests/std/test.lst index e0c06acf279..4959069e96d 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -159,6 +159,7 @@ tests\GH_000457_system_error_message tests\GH_000545_include_compare tests\GH_000685_condition_variable_any tests\GH_000690_overaligned_function +tests\GH_000890_pow_template tests\LWG3018_shared_ptr_function tests\P0024R2_parallel_algorithms_adjacent_difference tests\P0024R2_parallel_algorithms_adjacent_find diff --git a/tests/std/tests/GH_000890_pow_template/env.lst b/tests/std/tests/GH_000890_pow_template/env.lst new file mode 100644 index 00000000000..19f025bd0e6 --- /dev/null +++ b/tests/std/tests/GH_000890_pow_template/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_matrix.lst diff --git a/tests/std/tests/GH_000890_pow_template/test.cpp b/tests/std/tests/GH_000890_pow_template/test.cpp new file mode 100644 index 00000000000..a9967b3b6e8 --- /dev/null +++ b/tests/std/tests/GH_000890_pow_template/test.cpp @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +int main() {} // COMPILE-ONLY + +constexpr long double ld = 10.0l; +constexpr double d = 10.0; +constexpr float f = 10.0f; +constexpr long long ll = 2; +constexpr int i = 2; +constexpr short s = 2; + +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); + +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); + +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); + +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); + +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); + +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); +STATIC_ASSERT(std::is_same_v); diff --git a/tests/std/tests/VSO_0099869_pow_float_overflow/test.cpp b/tests/std/tests/VSO_0099869_pow_float_overflow/test.cpp index 3a8de4d7c99..a4c11a09a2c 100644 --- a/tests/std/tests/VSO_0099869_pow_float_overflow/test.cpp +++ b/tests/std/tests/VSO_0099869_pow_float_overflow/test.cpp @@ -44,7 +44,7 @@ class test_std_pow_against_crt { void single(uint32_t baseCandidate) { float input = reinterpret_as(baseCandidate); - float powOut = std::pow(input, 2); + float powOut = static_cast(pow(input, 2)); float powfOut = powf(input, 2.0f); int powClass = fpclassify(powOut); int powfClass = fpclassify(powfOut);