Skip to content

Commit c456934

Browse files
committed
Added negative cases for asinh according to IEEE-754.
1 parent 92f08b7 commit c456934

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/libstd/f32.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,17 @@ impl f32 {
908908
#[stable(feature = "rust1", since = "1.0.0")]
909909
#[inline]
910910
pub fn asinh(self) -> f32 {
911-
if self == NEG_INFINITY {
912-
NEG_INFINITY
913-
} else {
914-
(self + ((self * self) + 1.0).sqrt()).ln()
911+
match self {
912+
x if x == NEG_INFINITY => NEG_INFINITY,
913+
x if x.is_sign_negative() => {
914+
let v = (x + ((x * x) + 1.0).sqrt()).ln();
915+
if v.is_sign_negative() {
916+
v
917+
} else {
918+
-v
919+
}
920+
}
921+
x => (x + ((x * x) + 1.0).sqrt()).ln()
915922
}
916923
}
917924

src/libstd/f64.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,17 @@ impl f64 {
831831
#[stable(feature = "rust1", since = "1.0.0")]
832832
#[inline]
833833
pub fn asinh(self) -> f64 {
834-
if self == NEG_INFINITY {
835-
NEG_INFINITY
836-
} else {
837-
(self + ((self * self) + 1.0).sqrt()).ln()
834+
match self {
835+
x if x == NEG_INFINITY => NEG_INFINITY,
836+
x if x.is_sign_negative() => {
837+
let v = (x + ((x * x) + 1.0).sqrt()).ln();
838+
if v.is_sign_negative() {
839+
v
840+
} else {
841+
-v
842+
}
843+
}
844+
x => (x + ((x * x) + 1.0).sqrt()).ln()
838845
}
839846
}
840847

0 commit comments

Comments
 (0)