From 770beedb4466c02a8dc34fc0e1ef2af7bb421331 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 11 Feb 2023 12:01:52 -0330 Subject: constants --- src/lib.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index d8509d5..00163b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +use std::f64::consts::{E, PI}; + mod input; pub mod ui; @@ -61,8 +63,8 @@ enum Function { RSin, // Sine (radians) RCos, // Cosing (radians) RTan, // Tangent (radians) - Deg, // Convert from radians to degrees. - Rad, // Convert from degrees to radians. + Deg, // Convert from radians to degrees + Rad, // Convert from degrees to radians } impl Function { @@ -96,6 +98,30 @@ impl Function { struct ParseFunctionError(String); +enum Constant { + Pi, // Archimedes’ constant (π) + E, // Euler's number (e) +} + +impl Constant { + fn parse(s: &str) -> Result { + match s { + "pi" => Ok(Self::Pi), + "e" => Ok(Self::E), + _ => Err(ParseConstantError(s.to_string())), + } + } + + fn value(&self) -> f64 { + match self { + Self::Pi => PI, + Self::E => E, + } + } +} + +struct ParseConstantError(String); + pub enum Signal { None, Exit, -- cgit v1.2.3