chiark / gitweb /
limb type
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Oct 2020 18:58:17 +0000 (19:58 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Oct 2020 18:58:17 +0000 (19:58 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bigfloat.rs

index 91a31777ec18484ed98cece80fe604a09db26484..9a6032dba32ee0a00715c0f94f50e1d7ee2f9a3d 100644 (file)
@@ -7,13 +7,16 @@ enum Sign { Neg, Pos, }
 use Sign::*;
 
 type Sz = u16;
-type Limb = [u16;3];
 
 const CHARS_HEADER : usize = 5;
 const CHARS_PER_LIMB : usize = 15;
 
 pub use innards::Bigfloat;
 
+#[repr(transparent)]
+#[derive(Copy,Clone,Debug,Ord,PartialOrd,Eq,PartialEq)]
+struct Limb (pub [u16;3]);
+
 mod innards {
   use super::*;
   use std::mem::{self, align_of, size_of};
@@ -169,11 +172,11 @@ impl Bigfloat {
         Some(' ') => (),
         _ => None?,
       };
-      limbs.push([
+      limbs.push(Limb([
         p.hex16_()?,
         p.hex16_()?,
         p.hex16()?,
-      ]);
+      ]));
     }
     if limbs.is_empty() { None? }
     Bigfloat::from_parts(sign, exp, &limbs)
@@ -186,6 +189,15 @@ impl Bigfloat {
     write!(&mut s, "{}", self).unwrap();
     s
   }
+
+/*
+  fn add(&self, v: u32) -> Bigfloat {
+    let (h, l) = self.as_parts();
+    let l : Vec<_> = l.collect();
+
+    fn add_to_limb(&self, v: u32, );
+  }
+*/
 }
 
 impl Display for Bigfloat {
@@ -196,7 +208,7 @@ impl Display for Bigfloat {
            match h.sign { Pos => '+', Neg => '!', },
            h.exp)?;
     for l in ls {
-      write!(f, " {:04x}_{:04x}_{:04x}", l[0], l[1], l[2])?;
+      write!(f, " {:04x}_{:04x}_{:04x}", l.0[0], l.0[1], l.0[2])?;
     }
   }
 }