-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor for traits and docs; tag 0.1.0
- Loading branch information
Showing
10 changed files
with
670 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
max_width = 136 | ||
tab_spaces = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
Oops, something went wrong.