From 819e4443783dd5243009627582d6ad8df1598575 Mon Sep 17 00:00:00 2001 From: rm-dr <96270320+rm-dr@users.noreply.github.com> Date: Sun, 15 Oct 2023 11:42:40 -0700 Subject: [PATCH 1/3] Updated README --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 9f7e4ea..c4a0f32 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,7 @@ in # 🛠️ Features - Open-source - - Extremely high precision - - Uses a rational datatype when possible, and a high-precision float when not. - - Pretty printing in prompt (with special substitutions) + - Carefully designed and easy-to-read prompt - Supports many physical units, with metric and binary prefixes - Supports exponential notation - Clear syntax, parsed input is always re-printed as a sanity check. From b8bde580a33dacaaa7958dda9ec7da04d712e420 Mon Sep 17 00:00:00 2001 From: rm-dr <96270320+rm-dr@users.noreply.github.com> Date: Sun, 15 Oct 2023 12:07:09 -0700 Subject: [PATCH 2/3] Added CtoF and FtoC --- README.md | 4 ++++ src/command/mod.rs | 3 +++ src/evaluate/function.rs | 30 ++++++++++++++++++++++++++++++ src/parser/expression/function.rs | 11 ++++++++++- src/tests.rs | 6 ++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4a0f32..7029bf5 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,10 @@ Daisy instead provides four functions (`fromCelsius`, `toCelsius`, `fromFahrenhe - "from" functions take a scalar and return a value in Kelvin: `fromCelsius(0) = 273.15K` - "to" functions take a value in Kelvin and return a scalar: `toCelsius(273.15 K) = 0` +Functions `FtoC` and `CtoF` are also provided: + - `FtoC(x) = toCelsius(fromFahrenheit(x))` + - `CtoF(x) = toFahrenheit(fromCelsius(x))` + ## Multiplication Order diff --git a/src/command/mod.rs b/src/command/mod.rs index ee7bdf5..6d06278 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -152,6 +152,9 @@ pub fn do_command( " Fahrenheit to Kelvin [c]fromF, fromFahrenheit[n]\n", " Kelvin to Fahrenheit [c]toF, toFahrenheit[n]\n", "\n", + " Celsius to Fahrenheit [c]CtoF[n]\n", + " Fahrenheit to Celsius [c]FtoC[n]\n", + "\n", " convert to base unit [c]tobase[n]\n", " remove units [c]nounit[n]\n", "\n\n" diff --git a/src/evaluate/function.rs b/src/evaluate/function.rs index 5f3b101..ad8efc4 100644 --- a/src/evaluate/function.rs +++ b/src/evaluate/function.rs @@ -1,3 +1,5 @@ +use std::collections::VecDeque; + use crate::parser::Expression; use crate::parser::Function; use crate::parser::Operator; @@ -9,6 +11,7 @@ use crate::quantity::Quantity; use crate::quantity::Scalar; use crate::errors::DaisyError; use crate::context::Context; +use super::evaluate; // If unitless, do nothing // If compatible with radians, convert to radians and return unitless @@ -151,6 +154,33 @@ pub fn eval_function(context: &mut Context, g: &Expression) -> Result { + return Ok(evaluate(context, + &Expression::Operator( + *l + *loc, + Operator::Function(Function::ToFahrenheit), + VecDeque::from(vec![Expression::Operator( + *l + *loc, + Operator::Function(Function::FromCelsius), + VecDeque::from(vec![Expression::Quantity(*l, q.clone())]) + )]) + ) + ).ok()); + }, + + Function::FtoC => { + return Ok(evaluate(context, + &Expression::Operator( + *l + *loc, + Operator::Function(Function::ToCelsius), + VecDeque::from(vec![Expression::Operator( + *l + *loc, + Operator::Function(Function::FromFahrenheit), + VecDeque::from(vec![Expression::Quantity(*l, q.clone())]) + )]) + ) + ).ok()); + }, Function::ToCelsius => { let mut k = Quantity::new_rational(1f64).unwrap(); diff --git a/src/parser/expression/function.rs b/src/parser/expression/function.rs index 24482f7..b65f11c 100644 --- a/src/parser/expression/function.rs +++ b/src/parser/expression/function.rs @@ -37,7 +37,9 @@ pub enum Function { FromCelsius, ToCelsius, FromFahrenheit, - ToFahrenheit + ToFahrenheit, + CtoF, + FtoC, } @@ -74,6 +76,8 @@ impl ToString for Function { Function::ToCelsius => {String::from("tocelsius") }, Function::FromFahrenheit => { String::from("fromfahrenheit") }, Function::ToFahrenheit => { String::from("tofahrenheit") }, + Function::FtoC => { String::from("FtoC") }, + Function::CtoF => { String::from("CtoF") }, } } @@ -126,6 +130,11 @@ impl Function { "fromF" => {Some(Function::FromFahrenheit)}, "fromfahrenheit" => {Some(Function::FromFahrenheit)}, "fromFahrenheit" => {Some(Function::FromFahrenheit)}, + + "FtoC" => {Some(Function::FtoC)}, + "ftoc" => {Some(Function::FtoC)}, + "ctof" => {Some(Function::CtoF)}, + "CtoF" => {Some(Function::CtoF)}, _ => None } } diff --git a/src/tests.rs b/src/tests.rs index e765a57..c5d2e9d 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -232,5 +232,11 @@ fn functions() { good_expr("2", "nounit(2 mm)"); good_expr("2", "nounit(2 meter * second)"); + + good_expr("37.778", "FtoC(100)"); + good_expr("73.399", "CtoF(23)"); + good_expr("-17.778", "FtoC(0)"); + good_expr("31.999", "CtoF(0)"); + //good_expr("5000 m²·g/(s²·A²)", "tobase(5H)"); } \ No newline at end of file From 18a7d592ef1da59a864f3172021cc3f4bcbfa683 Mon Sep 17 00:00:00 2001 From: rm-dr <96270320+rm-dr@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:00:14 -0800 Subject: [PATCH 3/3] Edited description --- Cargo.toml | 2 +- README.md | 2 +- server/site/index.html | 2 +- src/command/mod.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2cdd545..32e5e63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "1.1.7" edition = "2021" build = "buildscript/main.rs" license = "GPL-3.0-only" -description = "A high-precision terminal scientific calculator." +description = "A pretty TUI scientific calculator." repository = "https://git.betalupi.com/Mark/daisy" homepage = "https://git.betalupi.com/Mark/daisy" readme = "README.md" diff --git a/README.md b/README.md index 7029bf5..d301b1f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![](./server/site/resources/readme-banner.png) -A high-precision scientific calculator with support for units, derivatives, and more. +A pretty, general-purpose scientific calculator with support for units, derivatives, and more. Many features are missing, this is still under development. diff --git a/server/site/index.html b/server/site/index.html index 9053391..becaefd 100644 --- a/server/site/index.html +++ b/server/site/index.html @@ -86,7 +86,7 @@
diff --git a/src/command/mod.rs b/src/command/mod.rs index 6d06278..2482387 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -57,8 +57,8 @@ pub fn do_command( t.push( concat!( - "Daisy is a high-precision, general-purpose\n", - "scientific calculator.\n", + "Daisy is a pretty, general-purpose\n", + "TUI scientific calculator.\n", "\n", " - Use Up/Down arrows to navigate history.\n", " - Use Ctrl-C or Ctrl-D to quit.\n",