correct float version of sign/1 (#1360)

This commit is contained in:
Mark Thom
2022-03-18 19:00:53 -06:00
parent 3d4e400ed2
commit c2fc33afec
5 changed files with 19 additions and 22 deletions

View File

@@ -627,6 +627,22 @@ impl ArenaFrom<Number> for HeapCellValue {
}
impl Number {
pub(crate) fn sign(&self) -> Number {
match self {
&Number::Float(f) if f == 0.0 => Number::Float(OrderedFloat(0f64)),
&Number::Float(f) => Number::Float(OrderedFloat(f.signum())),
_ => {
if self.is_positive() {
Number::Fixnum(Fixnum::build_with(1))
} else if self.is_negative() {
Number::Fixnum(Fixnum::build_with(-1))
} else {
Number::Fixnum(Fixnum::build_with(0))
}
}
}
}
#[inline]
pub(crate) fn is_positive(&self) -> bool {
match self {