Skip to content

Commit

Permalink
refactor for traits and docs; tag 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jul 7, 2022
1 parent 7cd4b6a commit ad51a35
Show file tree
Hide file tree
Showing 10 changed files with 670 additions and 592 deletions.
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

max_width = 136
tab_spaces = 2
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dual_balanced_ternary"
version = "0.1.0-a8"
edition = "2018"
version = "0.1.0"
edition = "2021"
license = "MIT"
description = "Dual Balanced Ternary Arithmetic"
homepage = "https://github.com/dual-balanced-ternary"
Expand Down
11 changes: 6 additions & 5 deletions examples/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use dual_balanced_ternary::{ternary, DualBalancedTernary};
use std::convert::{TryFrom, TryInto};

pub fn main() -> Result<(), String> {
println!("{:?}", ternary("&1.1").to_buffer());
println!("{:?}", ternary("&14.14").to_buffer());
println!("{:?}", TryInto::<Vec<u8>>::try_into(ternary("&1.1"))?);
println!("{:?}", TryInto::<Vec<u8>>::try_into(ternary("&14.14"))?);

println!("{:?}", DualBalancedTernary::from_buffer(&[1, 21, 21]));
println!("{:?}", DualBalancedTernary::from_buffer(&[1, 65, 20]));
println!("{:?}", DualBalancedTernary::try_from(&vec![1, 21, 21])?);
println!("{:?}", DualBalancedTernary::try_from(&vec![1, 65, 20]));

println!("TODO {:?}", ternary("&12.12").to_buffer()?);
println!("TODO {:?}", TryInto::<Vec<u8>>::try_into(ternary("&12.12"))?);

Ok(())
}
40 changes: 5 additions & 35 deletions src/complex.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@
use crate::digit::{DualBalancedTernaryDigit, DualBalancedTernaryDigit::*};

/// simple complex number struct
#[derive(PartialEq, Debug, Clone)]
pub struct ComplextXy {
pub struct ComplexXy {
pub x: f64,
pub y: f64,
}

// pub const fractional_base: i64 = 1 / 3;

pub fn to_digit(x: i64, y: i64) -> DualBalancedTernaryDigit {
match x {
-1 => match y {
-1 => Dbt2,
0 => Dbt7,
1 => Dbt6,
_ => unreachable!(format!("unexpected y: {}", y)),
},
0 => match y {
-1 => Dbt9,
0 => Dbt5,
1 => Dbt1,
_ => unreachable!(format!("unexpected y: {}", y)),
},
1 => match y {
-1 => Dbt8,
0 => Dbt3,
1 => Dbt4,
_ => unreachable!(format!("unexpected y: {}", y)),
},
_ => unreachable!(format!("unexpected x: {}", x)),
}
}

impl ComplextXy {
pub fn flip_xy(&self) -> ComplextXy {
ComplextXy {
x: self.y,
y: self.x,
}
impl ComplexXy {
pub fn flip_xy(&self) -> ComplexXy {
ComplexXy { x: self.y, y: self.x }
}
}
Loading

0 comments on commit ad51a35

Please sign in to comment.