|
18 | 18 | #define COLVARS_DEBUG false |
19 | 19 | #endif |
20 | 20 |
|
21 | | -#if defined(__FAST_MATH__) && defined(__aarch64__) |
| 21 | +#if defined(__FAST_MATH__) |
22 | 22 | // NOTE: This is used for fixing https://github.com/Colvars/colvars/issues/767 |
23 | 23 | #define COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC |
24 | 24 | #endif |
@@ -152,27 +152,42 @@ class colvarmodule { |
152 | 152 | return ::cos(static_cast<double>(x)); |
153 | 153 | } |
154 | 154 |
|
155 | | - /// Reimplemented to work around MS compiler issues |
156 | | - static inline real asin(real const &x) |
157 | | - { |
| 155 | +#ifndef PI |
| 156 | +#define PI 3.14159265358979323846 |
| 157 | +#define PI_2 1.57079632679489661923 |
| 158 | +#endif |
| 159 | + |
| 160 | +/// Reimplemented to work around compiler issues; return hard-coded values for boundary conditions |
| 161 | +static inline real asin(real const &x) |
| 162 | +{ |
158 | 163 | #ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC |
159 | | - const double tmp = static_cast<double>(x); |
160 | | - return ::asin(tmp > 1.0 ? 1.0 : (tmp < -1.0 ? -1.0 : tmp)); |
| 164 | + if (x <= -1.0) { |
| 165 | + return -PI_2; |
| 166 | + } else if (x >= 1.0) { |
| 167 | + return PI_2; |
| 168 | + } else { |
| 169 | + return ::asin(static_cast<double>(x)); |
| 170 | + } |
161 | 171 | #else |
162 | 172 | return ::asin(static_cast<double>(x)); |
163 | 173 | #endif |
164 | | - } |
| 174 | +} |
165 | 175 |
|
166 | | - /// Reimplemented to work around MS compiler issues |
167 | | - static inline real acos(real const &x) |
168 | | - { |
| 176 | +/// Reimplemented to work around compiler issues; return hard-coded values for boundary conditions |
| 177 | +static inline real acos(real const &x) |
| 178 | +{ |
169 | 179 | #ifdef COLVARS_BOUNDED_INV_TRIGONOMETRIC_FUNC |
170 | | - const double tmp = static_cast<double>(x); |
171 | | - return ::acos(tmp > 1.0 ? 1.0 : (tmp < -1.0 ? -1.0 : tmp)); |
| 180 | + if (x <= -1.0) { |
| 181 | + return PI; |
| 182 | + } else if (x >= 1.0) { |
| 183 | + return 0.0; |
| 184 | + } else { |
| 185 | + return ::acos(static_cast<double>(x)); |
| 186 | + } |
172 | 187 | #else |
173 | 188 | return ::acos(static_cast<double>(x)); |
174 | 189 | #endif |
175 | | - } |
| 190 | +} |
176 | 191 |
|
177 | 192 | /// Reimplemented to work around MS compiler issues |
178 | 193 | static inline real atan2(real const &x, real const &y) |
|
0 commit comments