forked from microsoft/STL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxfsinh.cpp
59 lines (48 loc) · 1.46 KB
/
xfsinh.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// _FSinh function
#include "xmath.h"
_EXTERN_C_UNLESS_PURE
// coefficients
static const float p[] = {0.00020400F, 0.00832983F, 0.16666737F, 0.99999998F};
_CRTIMP2_PURE float __CLRCALL_PURE_OR_CDECL _FSinh(float x, float y) { // compute y * sinh(x), |y| <= 1
short neg;
switch (_FDtest(&x)) { // test for special codes
case _NANCODE:
return x;
case _INFCODE:
return y != 0.0F ? x : FSIGN(x) ? -y : y;
case 0:
return x * y;
default: // finite
if (y == 0.0F) {
return x < 0.0F ? -y : y;
}
if (x < 0.0F) {
x = -x;
neg = 1;
} else {
neg = 0;
}
if (x < _FRteps._Float) {
x *= y; // x tiny
} else if (x < 1.0F) {
float w = x * x;
x += ((p[0] * w + p[1]) * w + p[2]) * w * x;
x *= y;
} else if (x < _FXbig) { // worth adding in exp(-x)
_FExp(&x, 1.0F, -1);
x = y * (x - 0.25F / x);
} else {
switch (_FExp(&x, y, -1)) { // report over/underflow
case 0:
_Feraise(_FE_UNDERFLOW);
break;
case _INFCODE:
_Feraise(_FE_OVERFLOW);
}
}
return neg ? -x : x;
}
}
_END_EXTERN_C_UNLESS_PURE