]> Repositorios git - scryer-prolog.git/commitdiff
correct float version of sign/1 (#1360)
authorMark Thom <[email protected]>
Sat, 19 Mar 2022 01:00:53 +0000 (19:00 -0600)
committerMark Thom <[email protected]>
Sat, 19 Mar 2022 21:55:23 +0000 (15:55 -0600)
Cargo.toml
src/forms.rs
src/machine/arithmetic_ops.rs
src/machine/dispatch.rs
src/machine/machine_state_impl.rs

index 3b0615fc481f665c9142d5210be688a5dec6ec1f..e74616d7a808527ab18074c29ad9db35879b8e02 100644 (file)
@@ -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 }
index a3c2b3547f0f336a6bfecd48a8b70de77e78ecbd..1b61546a1da59d9fadee6d10b54f2221b8843104 100644 (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 {
index 2541f0a1c5aca59e898ed18b90c0f769cb811889..b4378afdb61756802a99b3aa0d7e9dba52aac2db 100644 (file)
@@ -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);
index aaa22f1839604bb3aa1131a5b0de8c2218b85371..0a11068113691ec0bfd6546e2a63c29d58c36547 100644 (file)
@@ -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) => {
index 8cac8b92e0bc7ce50f17dcd307a6baee7e22e5ad..0f128e08b81359fd8a97c6c287be26d8746a0021 100644 (file)
@@ -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);