summaryrefslogtreecommitdiffstats
path: root/vendor/libm-0.1.4/src/math/acosh.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/libm-0.1.4/src/math/acosh.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/libm-0.1.4/src/math/acosh.rs')
-rw-r--r--vendor/libm-0.1.4/src/math/acosh.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/vendor/libm-0.1.4/src/math/acosh.rs b/vendor/libm-0.1.4/src/math/acosh.rs
new file mode 100644
index 000000000..ac7a5f1c6
--- /dev/null
+++ b/vendor/libm-0.1.4/src/math/acosh.rs
@@ -0,0 +1,26 @@
+use super::{log, log1p, sqrt};
+
+const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa39ef*/
+
+/// Inverse hyperbolic cosine (f64)
+///
+/// Calculates the inverse hyperbolic cosine of `x`.
+/// Is defined as `log(x + sqrt(x*x-1))`.
+/// `x` must be a number greater than or equal to 1.
+pub fn acosh(x: f64) -> f64 {
+ let u = x.to_bits();
+ let e = ((u >> 52) as usize) & 0x7ff;
+
+ /* x < 1 domain error is handled in the called functions */
+
+ if e < 0x3ff + 1 {
+ /* |x| < 2, up to 2ulp error in [1,1.125] */
+ return log1p(x - 1.0 + sqrt((x - 1.0) * (x - 1.0) + 2.0 * (x - 1.0)));
+ }
+ if e < 0x3ff + 26 {
+ /* |x| < 0x1p26 */
+ return log(2.0 * x - 1.0 / (x + sqrt(x * x - 1.0)));
+ }
+ /* |x| >= 0x1p26 or nan */
+ return log(x) + LN2;
+}