diff --git a/src/bin/ccc/mod.rs b/src/bin/ccc/mod.rs index 88d9532..9e48d5d 100644 --- a/src/bin/ccc/mod.rs +++ b/src/bin/ccc/mod.rs @@ -15,7 +15,7 @@ #![warn(clippy::pedantic)] //// IMPORTS /////////////////////////////////////////////////////////////////////////////////////// -use pt::math::computer::*; +use pt::math::computer::{*, self}; use pt::logger::*; use clap::{Parser, Subcommand}; @@ -126,7 +126,9 @@ fn main() { for part in cli.expression { expr += ∂ } - - info!("exporssion: {}", expr); + + debug!("exporssion: {}", expr); + let r = Computer::oneshot(expr); + println!("{}", r.unwrap()); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/bin/main/mod.rs b/src/bin/main/mod.rs index 86ca5f3..cea1cb7 100644 --- a/src/bin/main/mod.rs +++ b/src/bin/main/mod.rs @@ -15,7 +15,7 @@ //// IMPORTS /////////////////////////////////////////////////////////////////////////////////////// -use pt::{logger, networking::monitoring::uptime}; +use pt::{logger, networking::monitoring::uptime, common::*}; // we want the log macros in any case #[allow(unused_imports)] @@ -30,8 +30,6 @@ use std::path::PathBuf; //// CONSTANTS ///////////////////////////////////////////////////////////////////////////////////// #[allow(dead_code)] -const EXIT_SUCCESS: i32 = 0; -const EXIT_FAILURE_USAGE: i32 = 1; //// STATICS /////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/common/mod.rs b/src/common/mod.rs index 2c1382e..6f1467b 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -23,6 +23,8 @@ pub mod macros; pub mod printing; //// CONSTANTS ///////////////////////////////////////////////////////////////////////////////////// +pub const EXIT_SUCCESS: i32 = 0; +pub const EXIT_FAILURE_USAGE: i32 = 1; //// STATICS /////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/math/computer/mod.rs b/src/math/computer/mod.rs index e5911b6..043f920 100644 --- a/src/math/computer/mod.rs +++ b/src/math/computer/mod.rs @@ -30,15 +30,38 @@ use crate::logger::{trace, debug, info, warn, error}; //// MACROS //////////////////////////////////////////////////////////////////////////////////////// //// ENUMS ///////////////////////////////////////////////////////////////////////////////////////// -#[non_exhaustive] -pub enum Constants { - Pi -} +// #[non_exhaustive] +// #[derive(Debug)] +// pub enum Constants { +// Pi +// } //////////////////////////////////////////////////////////////////////////////////////////////////// #[non_exhaustive] +#[derive(Debug)] +/// ## Supported Operations +/// +/// This `enum` contains all operations supported in this module. pub enum Operations { - Addit + /// Mathmatical addition + Addition, + /// Mathmatical subtraction + Subtraction, + /// Mathmatical multiplication + Multiplication, + /// Mathmatical division + Division, + /// Mathmatical modulo, finite field arithmetic + Modulo, + /// Draw the mathmatical root, attribute n is the nth root + Root(u16), + /// round up + Floor, + /// round down + Ceil, + /// round to nearest integer + /// (commercial rounding) + Round } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -48,11 +71,11 @@ pub enum Functions { } //// STRUCTS /////////////////////////////////////////////////////////////////////////////////////// -struct Computer; +pub struct Computer; //////////////////////////////////////////////////////////////////////////////////////////////////// #[derive(Debug)] -struct Term { +pub struct Term { original: String, result: Option, parts: Vec diff --git a/src/math/computer/result.rs b/src/math/computer/result.rs index ccc588a..35f0406 100644 --- a/src/math/computer/result.rs +++ b/src/math/computer/result.rs @@ -12,6 +12,7 @@ #![warn(clippy::pedantic)] //// IMPORTS /////////////////////////////////////////////////////////////////////////////////////// +use std::fmt::Display; use num_traits; //// TYPES ///////////////////////////////////////////////////////////////////////////////////////// @@ -52,6 +53,7 @@ pub struct VarResult { } +//////////////////////////////////////////////////////////////////////////////////////////////////// #[derive(Debug)] pub struct ComplexResult { @@ -75,6 +77,7 @@ impl From for NumericResult where } } +//////////////////////////////////////////////////////////////////////////////////////////////////// impl From for ComputeResult where u128: TryFrom, u128: TryFrom { @@ -83,12 +86,61 @@ impl From for ComputeResult where } } +//////////////////////////////////////////////////////////////////////////////////////////////////// impl From for ComputeResult { fn from(value: NumericResult) -> Self { ComputeResult::Numerical(value) } } +//////////////////////////////////////////////////////////////////////////////////////////////////// +impl Display for ComputeResult { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ComputeResult::Numerical(val) => { + write!(f, "{}", val) + } + ComputeResult::Complex(val) => { + write!(f, "{}", val) + } + ComputeResult::Variable(val) => { + write!(f, "{}", val) + } + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +impl Display for NumericResult { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + NumericResult::Float(val) => { + write!(f, "{val}") + } + NumericResult::Signed(val) => { + write!(f, "{val}") + } + NumericResult::Unsigned(val) => { + write!(f, "{val}") + } + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +impl Display for ComplexResult { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "") + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +impl Display for VarResult { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "") + } +} + //// PUBLIC FUNCTIONS ////////////////////////////////////////////////////////////////////////////// //// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////