correct float version of sign/1 (#1360)
This commit is contained in:
@@ -45,7 +45,7 @@ libc = "0.2.62"
|
||||
modular-bitfield = "0.11.2"
|
||||
nix = "0.15.0"
|
||||
num-rug-adapter = { version = "0.1.6", optional = true }
|
||||
ordered-float = "2.1.1"
|
||||
ordered-float = "2.6.0"
|
||||
phf = { version = "0.9", features = ["macros"] }
|
||||
ref_thread_local = "0.0.0"
|
||||
rug = { version = "1.15.0", optional = true }
|
||||
|
||||
16
src/forms.rs
16
src/forms.rs
@@ -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 {
|
||||
|
||||
@@ -82,16 +82,6 @@ fn numerical_type_error(
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn sign(n: Number) -> Number {
|
||||
if n.is_positive() {
|
||||
Number::Fixnum(Fixnum::build_with(1))
|
||||
} else if n.is_negative() {
|
||||
Number::Fixnum(Fixnum::build_with(-1))
|
||||
} else {
|
||||
Number::Fixnum(Fixnum::build_with(0))
|
||||
}
|
||||
}
|
||||
|
||||
fn isize_gcd(n1: isize, n2: isize) -> Option<isize> {
|
||||
if n1 == 0 {
|
||||
return n2.checked_abs().map(|n| n as isize);
|
||||
@@ -1278,7 +1268,7 @@ impl MachineState {
|
||||
atom!("\\") => self.interms.push(
|
||||
drop_iter_on_err!(self, iter, bitwise_complement(a1, &mut self.arena))
|
||||
),
|
||||
atom!("sign") => self.interms.push(sign(a1)),
|
||||
atom!("sign") => self.interms.push(a1.sign()),
|
||||
_ => {
|
||||
let evaluable_stub = functor_stub(name, 1);
|
||||
std::mem::drop(iter);
|
||||
|
||||
@@ -714,7 +714,7 @@ impl Machine {
|
||||
&Instruction::Sign(ref a1, t) => {
|
||||
let n = try_or_throw!(self.machine_st, self.machine_st.get_number(a1));
|
||||
|
||||
self.machine_st.interms[t - 1] = sign(n);
|
||||
self.machine_st.interms[t - 1] = n.sign();
|
||||
self.machine_st.p += 1;
|
||||
}
|
||||
&Instruction::Neg(ref a1, t) => {
|
||||
|
||||
@@ -2594,15 +2594,6 @@ impl MachineState {
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn setup_built_in_call(&mut self, ct: BuiltInClauseType) {
|
||||
self.num_of_args = ct.arity();
|
||||
self.b0 = self.b;
|
||||
|
||||
self.p = CodePtr::BuiltInClause(ct, self.p.local());
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn deallocate(&mut self) {
|
||||
let e = self.e;
|
||||
let frame = self.stack.index_and_frame(e);
|
||||
|
||||
Reference in New Issue
Block a user