Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5077f20
Fuse xfcosh.cpp into xcosh.cpp.
StephanTLavavej Dec 11, 2025
ffcaac1
Fuse xfsinh.cpp into xsinh.cpp.
StephanTLavavej Dec 11, 2025
fdb8401
Fuse xfdtest.cpp into xdtest.cpp.
StephanTLavavej Dec 12, 2025
e0ca27b
Fuse xfexp.cpp into xexp.cpp.
StephanTLavavej Dec 11, 2025
cbf7497
Fuse xfdscale.cpp into xexp.cpp.
StephanTLavavej Dec 12, 2025
05e05ca
Fuse xfdnorm.cpp into xexp.cpp.
StephanTLavavej Dec 12, 2025
24d50a0
Replace `_Feraise()` with `errno = ERANGE;`.
StephanTLavavej Dec 12, 2025
0cf8a8b
Fuse underflow/overflow cases, avoid missing `break;`.
StephanTLavavej Dec 12, 2025
1485cc9
Preserve `_Dtest()` for bincompat, replaced with `fpclassify()`.
StephanTLavavej Dec 12, 2025
ec5d314
`_FINITE` => `FP_NORMAL`
StephanTLavavej Dec 12, 2025
067bf92
`_INFCODE` => `FP_INFINITE`
StephanTLavavej Dec 12, 2025
a12cfce
`_NANCODE` => `FP_NAN`
StephanTLavavej Dec 12, 2025
c548b9a
`0` => `FP_ZERO`, carefully.
StephanTLavavej Dec 12, 2025
4330caa
Remove now-unused `_Dtest()` macros.
StephanTLavavej Dec 12, 2025
d8dfbd5
Replace `DSIGN` and `FSIGN` with `signbit()`.
StephanTLavavej Dec 12, 2025
340232d
Move `_Dval`, `_Fval`, and their index macros into xexp.cpp's unnamed…
StephanTLavavej Dec 12, 2025
bb230a5
Change index macros to `constexpr int`, cleanup comments.
StephanTLavavej Dec 12, 2025
a6d8c16
Move `_Xfe_overflow()`, `_Xfe_underflow()` into xexp.cpp's unnamed na…
StephanTLavavej Dec 12, 2025
e56b8f8
Replace `extern const` `_Xbig` and `_FXbig` with replicated `constexpr`.
StephanTLavavej Dec 12, 2025
055190c
Delete xmath.hpp, include only relevant headers.
StephanTLavavej Dec 12, 2025
a85563e
Fix dangerous `_Dval`, `_Fval` union sizes.
StephanTLavavej Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions stl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,6 @@ set(SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/xdateord.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xdtest.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xexp.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xfcosh.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xfdnorm.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xfdscale.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xfdtest.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xferaise.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xfexp.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xfsinh.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xgetwctype.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xlgamma.cpp
${CMAKE_CURRENT_LIST_DIR}/src/xlocale.cpp
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/complex
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public:

static bool _Isinf(_Ty _Left) noexcept { // test for infinity
#if defined(__LDBL_DIG__) && __LDBL_DIG__ == 18
return _CSTD _LDtest(&_Left) == _INFCODE;
return _CSTD _LDtest(&_Left) == FP_INFINITE;
#else // ^^^ 80-bit long double (not supported by MSVC in general, see GH-1316) / 64-bit long double vvv
const auto _Uint = _Bit_cast<uint64_t>(_Left);
return (_Uint & 0x7fffffffffffffffU) == 0x7ff0000000000000U;
Expand All @@ -556,7 +556,7 @@ public:

static _CONSTEXPR20 bool _Isnan(_Ty _Left) noexcept {
#if defined(__LDBL_DIG__) && __LDBL_DIG__ == 18
return _CSTD _LDtest(&_Left) == _NANCODE;
return _CSTD _LDtest(&_Left) == FP_NAN;
#else // ^^^ 80-bit long double (not supported by MSVC in general, see GH-1316) / 64-bit long double vvv
const auto _Uint = _Bit_cast<uint64_t>(_Left);
return (_Uint & 0x7fffffffffffffffU) > 0x7ff0000000000000U;
Expand Down
4 changes: 0 additions & 4 deletions stl/inc/ymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ _STL_DISABLE_CLANG_WARNINGS

_EXTERN_C_UNLESS_PURE

// macros for _Dtest return (0 => ZERO)
#define _INFCODE 1
#define _NANCODE 2

_CRTIMP2_PURE double __CLRCALL_PURE_OR_CDECL _Cosh(double, double) noexcept;
_CRTIMP2_PURE double __CLRCALL_PURE_OR_CDECL _Sinh(double, double) noexcept;
_CRTIMP2_PURE short __CLRCALL_PURE_OR_CDECL _Exp(double*, double, short) noexcept;
Expand Down
7 changes: 0 additions & 7 deletions stl/msbuild/stl_base/stl.files.settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
<ClCompile Include="$(CrtRoot)\github\stl\src\xdateord.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xdtest.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xexp.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xfcosh.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xfdnorm.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xfdscale.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xfdtest.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xferaise.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xfexp.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xfsinh.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xgetwctype.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xlgamma.cpp" />
<ClCompile Include="$(CrtRoot)\github\stl\src\xlocale.cpp" />
Expand Down
53 changes: 43 additions & 10 deletions stl/src/xcosh.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "xmath.hpp"
#include <cerrno>
#include <cmath>
#include <ymath.h>

_EXTERN_C_UNLESS_PURE

_CRTIMP2_PURE double __CLRCALL_PURE_OR_CDECL _Cosh(double x, double y) noexcept { // compute y * cosh(x), |y| <= 1
switch (_Dtest(&x)) { // test for special codes
case _NANCODE:
case _INFCODE:
switch (_STD fpclassify(x)) { // test for special codes
case FP_NAN:
case FP_INFINITE:
return x;
case 0:
case FP_ZERO:
return y;
default: // finite
if (y == 0.0) {
Expand All @@ -21,16 +23,16 @@ _CRTIMP2_PURE double __CLRCALL_PURE_OR_CDECL _Cosh(double x, double y) noexcept
x = -x;
}

constexpr double _Xbig = ((48 + _DOFF) + 2) * 0.347;
if (x < _Xbig) { // worth adding in exp(-x)
_Exp(&x, 1.0, -1);
return y * (x + 0.25 / x);
}
switch (_Exp(&x, y, -1)) { // report over/underflow
case 0:
_Feraise(_FE_UNDERFLOW);
switch (_Exp(&x, y, -1)) {
case FP_ZERO: // report underflow
case FP_INFINITE: // report overflow
errno = ERANGE;
break;
case _INFCODE:
_Feraise(_FE_OVERFLOW);
}
return x;
}
Expand All @@ -40,4 +42,35 @@ _CRTIMP2_PURE long double __CLRCALL_PURE_OR_CDECL _LCosh(long double x, long dou
return _Cosh(static_cast<double>(x), static_cast<double>(y));
}

_CRTIMP2_PURE float __CLRCALL_PURE_OR_CDECL _FCosh(float x, float y) noexcept { // compute y * cosh(x), |y| <= 1
switch (_STD fpclassify(x)) { // test for special codes
case FP_NAN:
case FP_INFINITE:
return x;
case FP_ZERO:
return y;
default: // finite
if (y == 0.0) {
return y;
}

if (x < 0.0) {
x = -x;
}

constexpr float _FXbig = ((16 + _FOFF) + 2) * 0.347f;
if (x < _FXbig) { // worth adding in exp(-x)
_FExp(&x, 1.0F, -1);
return y * (x + 0.25F / x);
}
switch (_FExp(&x, y, -1)) {
case FP_ZERO: // report underflow
case FP_INFINITE: // report overflow
errno = ERANGE;
break;
}
return x;
}
}

_END_EXTERN_C_UNLESS_PURE
26 changes: 11 additions & 15 deletions stl/src/xdtest.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// _Dtest function -- IEEE 754 version

#include "xmath.hpp"
#include <cmath>

_EXTERN_C_UNLESS_PURE

_CRTIMP2_PURE short __CLRCALL_PURE_OR_CDECL _Dtest(double* px) noexcept { // categorize *px
const auto ps = reinterpret_cast<_Dval*>(px);

if ((ps->_Sh[_D0] & _DMASK) == _DMAX << _DOFF) {
return (ps->_Sh[_D0] & _DFRAC) != 0 || ps->_Sh[_D1] != 0 || ps->_Sh[_D2] != 0 || ps->_Sh[_D3] != 0 ? _NANCODE
: _INFCODE;
} else if ((ps->_Sh[_D0] & ~_DSIGN) != 0 || ps->_Sh[_D1] != 0 || ps->_Sh[_D2] != 0 || ps->_Sh[_D3] != 0) {
return (ps->_Sh[_D0] & _DMASK) == 0 ? _DENORM : _FINITE;
} else {
return 0;
}
// TRANSITION, ABI: preserved for binary compatibility
_CRTIMP2_PURE short __CLRCALL_PURE_OR_CDECL _Dtest(double* px) noexcept {
return static_cast<short>(_STD fpclassify(*px));
}

_CRTIMP2_PURE short __CLRCALL_PURE_OR_CDECL _LDtest(long double* px) noexcept { // categorize *px -- 64-bit
// TRANSITION, ABI: preserved for binary compatibility
_CRTIMP2_PURE short __CLRCALL_PURE_OR_CDECL _LDtest(long double* px) noexcept {
return _Dtest(reinterpret_cast<double*>(px));
}

// TRANSITION, ABI: preserved for binary compatibility
_CRTIMP2_PURE short __CLRCALL_PURE_OR_CDECL _FDtest(float* px) noexcept {
return static_cast<short>(_STD fpclassify(*px));
}

_END_EXTERN_C_UNLESS_PURE
Loading