Lines 1-5
Link Here
|
1 |
/*- |
1 |
/*- |
2 |
* Copyright (c) 2017 Steven G. Kargl |
2 |
* Copyright (c) 2017-2021 Steven G. Kargl |
3 |
* All rights reserved. |
3 |
* All rights reserved. |
4 |
* |
4 |
* |
5 |
* Redistribution and use in source and binary forms, with or without |
5 |
* Redistribution and use in source and binary forms, with or without |
Lines 26-34
Link Here
|
26 |
|
26 |
|
27 |
/* |
27 |
/* |
28 |
* See ../src/s_tanpi.c for implementation details. |
28 |
* See ../src/s_tanpi.c for implementation details. |
29 |
* |
|
|
30 |
* FIXME: This has not been compiled nor has it been tested for accuracy. |
31 |
* FIXME: This should use bit twiddling. |
32 |
*/ |
29 |
*/ |
33 |
|
30 |
|
34 |
#include "math.h" |
31 |
#include "math.h" |
Lines 75-81
tanpil(long double x)
Link Here
|
75 |
long double ax, hi, lo, xf, t; |
72 |
long double ax, hi, lo, xf, t; |
76 |
uint32_t ix; |
73 |
uint32_t ix; |
77 |
|
74 |
|
78 |
ax = fabsl(ax); |
75 |
ax = fabsl(x); |
79 |
|
76 |
|
80 |
if (ax < 1) { |
77 |
if (ax < 1) { |
81 |
if (ax < 0.5) { |
78 |
if (ax < 0.5) { |
Lines 94-112
tanpil(long double x)
Link Here
|
94 |
return ((ax - ax) / (ax - ax)); |
91 |
return ((ax - ax) / (ax - ax)); |
95 |
else |
92 |
else |
96 |
t = -__kernel_tanpil(1 - ax); |
93 |
t = -__kernel_tanpil(1 - ax); |
97 |
return (copysignl(t, x)); |
94 |
return (x < 0 ? -t : t); |
98 |
} |
95 |
} |
99 |
|
96 |
|
100 |
if (ix < 0x1p112) { |
97 |
if (ix < 0x1p112) { |
101 |
xf = floorl(ax); |
98 |
/* Split x = n + r with 0 <= r < 1. */ |
102 |
ax -= xf; |
99 |
xf = (ax + 0x1p112L) - 0x1p112L; /* Integer part */ |
|
|
100 |
ax -= xf; /* Remainder */ |
101 |
if (ax < 0) { |
102 |
ax += 1; |
103 |
xf -= 1; |
104 |
} |
105 |
|
103 |
if (ax < 0.5) |
106 |
if (ax < 0.5) |
104 |
t = ax == 0 ? 0 : __kernel_tanpil(ax); |
107 |
t = ax == 0 ? 0 : __kernel_tanpil(ax); |
105 |
else if (ax == 0.5) |
108 |
else if (ax == 0.5) |
106 |
return ((ax - ax) / (ax - ax)); |
109 |
return ((ax - ax) / (ax - ax)); |
107 |
else |
110 |
else |
108 |
t = -__kernel_tanpil(1 - ax); |
111 |
t = -__kernel_tanpil(1 - ax); |
109 |
return (copysignl(t, x)); |
112 |
return (x < 0 ? -t : t); |
110 |
} |
113 |
} |
111 |
|
114 |
|
112 |
/* x = +-inf or nan. */ |
115 |
/* x = +-inf or nan. */ |
Lines 114-120
tanpil(long double x)
Link Here
|
114 |
return (vzero / vzero); |
117 |
return (vzero / vzero); |
115 |
|
118 |
|
116 |
/* |
119 |
/* |
117 |
* |x| >= 0x1p53 is always an integer, so return +-0. |
120 |
* |x| >= 0x1p112 is always an integer, so return +-0. |
118 |
*/ |
121 |
*/ |
119 |
return (copysignl(0, x)); |
122 |
return (copysignl(0, x)); |
120 |
} |
123 |
} |