mirror of
https://github.com/rm-dr/daisy
synced 2025-07-01 06:33:34 -07:00
Compare commits
31 Commits
v1.1.4
...
1fae11a380
Author | SHA1 | Date | |
---|---|---|---|
1fae11a380
|
|||
bc1716eefd
|
|||
42555e0df7
|
|||
cd1074d30f
|
|||
937b45e3b0
|
|||
7726eea34d
|
|||
6fd315a9fe
|
|||
0d81d58370
|
|||
2ff42bf62a
|
|||
b5a23f814f
|
|||
e3e23a686d
|
|||
93c34ca4a4
|
|||
80f17ac210 | |||
3c8ed9f4f3 | |||
27ea64e172 | |||
b7a6378589 | |||
d6f1ce0442 | |||
5e34017225 | |||
d9730fd699
|
|||
5788ffa085
|
|||
a75f6197cd | |||
2f2c005c86
|
|||
ffebcf2e15
|
|||
4e1df2399b | |||
5a921cfc7b | |||
2531524ffd
|
|||
e5525adcca
|
|||
a61cbf29e5
|
|||
39ab47530e | |||
be28669416
|
|||
63d4a01095 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
/src/target
|
/src/target
|
||||||
/pkg
|
/pkg
|
||||||
|
/result
|
32
CONTRIBUTING.MD
Normal file
32
CONTRIBUTING.MD
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Contribution guidelines for Daisy
|
||||||
|
|
||||||
|
|
||||||
|
## Pull requests
|
||||||
|
All PRs should merge to `dev`. See "branching" below.
|
||||||
|
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
Daisy uses [semantic versioning](https://semver.org/), which looks like `maj.min.patch`. In short:
|
||||||
|
- `maj`: Incremented on large, incompatible changes
|
||||||
|
- `min`: Incremented on new features
|
||||||
|
- `patch`: Incremented on bugfixes
|
||||||
|
|
||||||
|
Whenever one of the above fields is incremented, all sub-fields are reset to zero. When `min` is incremented, `patch` is set to zero.
|
||||||
|
|
||||||
|
|
||||||
|
## Branching
|
||||||
|
Daisy uses a branch model much like the one described [here](https://nvie.com/posts/a-successful-git-branching-model).
|
||||||
|
- `master`: 1 commit = 1 release. This is always a merge comit from `dev`, and is always tagged with a version.
|
||||||
|
- `dev`: main development branch. Never deleted. Most work happens here.
|
||||||
|
- `features`: temporary branches pulled from `dev` and merged to `dev` for larger features.
|
||||||
|
- Always merge with git's `--no-ff` option for a more detailed history.
|
||||||
|
|
||||||
|
|
||||||
|
## Releases
|
||||||
|
What to do
|
||||||
|
- Merge into `master` (`git merge --no-ff dev`)
|
||||||
|
- Tag merge commit on `master` (`git tag -a v1.0.0 -m "Version 1.0.0"`)
|
||||||
|
- `cargo publish`
|
||||||
|
- Update web demo & pull server (`make docker`)
|
||||||
|
- Update aur package
|
||||||
|
- Update `default.nix` (test with `make nix`)
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -28,7 +28,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "daisycalc"
|
name = "daisycalc"
|
||||||
version = "1.1.4"
|
version = "1.1.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"num",
|
"num",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "daisycalc"
|
name = "daisycalc"
|
||||||
version = "1.1.4"
|
version = "1.1.7"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "buildscript/main.rs"
|
build = "buildscript/main.rs"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
|
8
Makefile
8
Makefile
@ -1,6 +1,9 @@
|
|||||||
release:
|
release:
|
||||||
cargo build --release
|
cargo build --release
|
||||||
|
|
||||||
|
nix:
|
||||||
|
nix-build -E 'let pkgs = import <nixpkgs> { }; in pkgs.callPackage ./default.nix {}'
|
||||||
|
|
||||||
test:
|
test:
|
||||||
cargo test
|
cargo test
|
||||||
|
|
||||||
@ -14,5 +17,6 @@ publish:
|
|||||||
cargo test
|
cargo test
|
||||||
cargo publish
|
cargo publish
|
||||||
|
|
||||||
docker:
|
docker: wasm
|
||||||
docker build ./server -t git.betalupi.com/mark/daisy
|
docker build ./server -t git.betalupi.com/mark/daisy --no-cache
|
||||||
|
docker push git.betalupi.com/mark/daisy
|
||||||
|
18
README.md
18
README.md
@ -7,13 +7,25 @@ Many features are missing, this is still under development.
|
|||||||
**Web demo: [here](https://daisy.betalupi.com) (won't work on mobile)**
|
**Web demo: [here](https://daisy.betalupi.com) (won't work on mobile)**
|
||||||
|
|
||||||
# 📦 Installation
|
# 📦 Installation
|
||||||
|
- **From source:** `cargo build --release`, binary will be at `./target/release/daisy`
|
||||||
- **Cargo:** `cargo install daisycalc`
|
- **Cargo:** `cargo install daisycalc`
|
||||||
- **Arch:** `yay -S daisy`
|
- **Arch:** `yay -S daisy`
|
||||||
- **Debian:** coming soon
|
- **Debian:** coming soon
|
||||||
|
- **Nix:** Use `default.nix`. Daisy isn't in nixpkgs yet, you'll need to add something like the following to `configuration.nix`:
|
||||||
|
|
||||||
From source: `cargo build --release` \
|
```nix
|
||||||
Binary will be in `target/release/daisy`
|
let
|
||||||
|
daisy = builtins.fetchGit {
|
||||||
|
url = "https://github.com/rm-dr/daisy.git";
|
||||||
|
ref = "master";
|
||||||
|
} + /default.nix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
(callPackage daisy { })
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# 📹 Screenshot
|
# 📹 Screenshot
|
||||||
|
|
||||||
|
22
TODO.md
22
TODO.md
@ -1,19 +1,3 @@
|
|||||||
## Version Bump checklist
|
|
||||||
- update Cargo.toml
|
|
||||||
- run cargo test
|
|
||||||
- commit
|
|
||||||
- push
|
|
||||||
- merge
|
|
||||||
- git tag -a v1.0.0 -m "Version 1.0.0" on merge commit
|
|
||||||
- cargo publish
|
|
||||||
- Build wasm & push changes
|
|
||||||
- Update AUR package
|
|
||||||
|
|
||||||
## Pre-release
|
|
||||||
- Tuple operations
|
|
||||||
- we don't need vectors as arguments to operators
|
|
||||||
- Fix linelocation when evaluating functions
|
|
||||||
|
|
||||||
## Parser
|
## Parser
|
||||||
- Should functions be operators?
|
- Should functions be operators?
|
||||||
- Binary, hex, octal numbers
|
- Binary, hex, octal numbers
|
||||||
@ -26,6 +10,7 @@
|
|||||||
- Non-recursive treeify
|
- Non-recursive treeify
|
||||||
- Faster factorial function. Maybe use gamma instead?
|
- Faster factorial function. Maybe use gamma instead?
|
||||||
- Arbitrary precision floats
|
- Arbitrary precision floats
|
||||||
|
- we don't need vectors as arguments to operators
|
||||||
|
|
||||||
## Math Features
|
## Math Features
|
||||||
- Mean, Median, Min
|
- Mean, Median, Min
|
||||||
@ -34,6 +19,9 @@
|
|||||||
- acot/acoth functions
|
- acot/acoth functions
|
||||||
- Sums and products with functional arguments
|
- Sums and products with functional arguments
|
||||||
- Add functions: gcd, inverse mod, dice
|
- Add functions: gcd, inverse mod, dice
|
||||||
|
- Tuple operations
|
||||||
|
- Number theory: select a group, inverses, etc
|
||||||
|
- Negative mod
|
||||||
|
|
||||||
## Prompt
|
## Prompt
|
||||||
- Fix terminal color detection
|
- Fix terminal color detection
|
||||||
@ -47,5 +35,5 @@
|
|||||||
- long prefixes (megatonne, etc)
|
- long prefixes (megatonne, etc)
|
||||||
- HMS for degrees
|
- HMS for degrees
|
||||||
- Exact radians, using pi constant?
|
- Exact radians, using pi constant?
|
||||||
- Weird units: flops, lumen, lux, bel
|
- Odd units: flops, lumen, lux, bel
|
||||||
- Command to list units
|
- Command to list units
|
@ -49,7 +49,7 @@ value = "1.602176634e-19 C"
|
|||||||
enum_name = "ElectronMass"
|
enum_name = "ElectronMass"
|
||||||
pretty_name = "Electron mass"
|
pretty_name = "Electron mass"
|
||||||
strings = ["electronmass"]
|
strings = ["electronmass"]
|
||||||
value = "9.1093837015-31 kg"
|
value = "9.1093837015e-31 kg"
|
||||||
|
|
||||||
[[constant]]
|
[[constant]]
|
||||||
enum_name = "ProtonMass"
|
enum_name = "ProtonMass"
|
||||||
|
19
default.nix
Normal file
19
default.nix
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{ lib, fetchgit, rustPlatform }:
|
||||||
|
rustPlatform.buildRustPackage rec {
|
||||||
|
pname = "daisy";
|
||||||
|
version = "1.1.7";
|
||||||
|
cargoLock.lockFile = src + /Cargo.lock;
|
||||||
|
|
||||||
|
src = builtins.fetchGit {
|
||||||
|
url = "https://github.com/rm-dr/daisy.git";
|
||||||
|
ref = "refs/tags/v${version}";
|
||||||
|
#rev = ""; Ideally, we'd have a hash here, but that would make git history messy.
|
||||||
|
};
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "A general-purpose scientific calculator";
|
||||||
|
homepage = "https://github.com/rm-dr/daisy";
|
||||||
|
#license = licenses.GPL;
|
||||||
|
maintainers = [ maintainers.tailhook ];
|
||||||
|
};
|
||||||
|
}
|
@ -247,7 +247,7 @@ pub fn do_command(
|
|||||||
if args.len() != 2 {
|
if args.len() != 2 {
|
||||||
return FormattedText::new(
|
return FormattedText::new(
|
||||||
format!(
|
format!(
|
||||||
"[c]{first}[n] [t]takes exactly one argument.[n]\n\n",
|
"[c]{first}[n] [e]takes exactly one argument.[n]\n\n",
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ pub fn do_command(
|
|||||||
Err(()) => {
|
Err(()) => {
|
||||||
FormattedText::new(
|
FormattedText::new(
|
||||||
format!(
|
format!(
|
||||||
"[c]{v}[n] [t]isn't a variable.[n]\n\n",
|
"[c]{v}[n] [e]isn't a variable.[n]\n\n",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ impl Context {
|
|||||||
|
|
||||||
pub fn delete(&mut self, s: &String) -> Result<(), ()> {
|
pub fn delete(&mut self, s: &String) -> Result<(), ()> {
|
||||||
if !(self.is_varible(s) || self.is_function(s)) { return Err(()) };
|
if !(self.is_varible(s) || self.is_function(s)) { return Err(()) };
|
||||||
|
if s == "ans" { return Err(()) };
|
||||||
if self.is_varible(s) { self.variables.remove(s); }
|
if self.is_varible(s) { self.variables.remove(s); }
|
||||||
if self.is_function(s) { self.functions.remove(s); }
|
if self.is_function(s) { self.functions.remove(s); }
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -63,7 +63,7 @@ pub fn evaluate(
|
|||||||
|
|
||||||
context.get_variable(&s)
|
context.get_variable(&s)
|
||||||
},
|
},
|
||||||
Expression::Operator(_, Operator::Function(_), _) => { eval_function(g)? },
|
Expression::Operator(_, Operator::Function(_), _) => { eval_function(context, g)? },
|
||||||
Expression::Operator(_, _, _) => { eval_operator(context, g)? },
|
Expression::Operator(_, _, _) => { eval_operator(context, g)? },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,11 +3,12 @@ use crate::parser::Function;
|
|||||||
use crate::parser::Operator;
|
use crate::parser::Operator;
|
||||||
use crate::parser::LineLocation;
|
use crate::parser::LineLocation;
|
||||||
use crate::quantity::FreeUnit;
|
use crate::quantity::FreeUnit;
|
||||||
|
use crate::quantity::Unit;
|
||||||
use crate::quantity::WholeUnit;
|
use crate::quantity::WholeUnit;
|
||||||
use crate::quantity::Quantity;
|
use crate::quantity::Quantity;
|
||||||
use crate::quantity::Scalar;
|
use crate::quantity::Scalar;
|
||||||
use crate::errors::DaisyError;
|
use crate::errors::DaisyError;
|
||||||
|
use crate::context::Context;
|
||||||
|
|
||||||
// If unitless, do nothing
|
// If unitless, do nothing
|
||||||
// If compatible with radians, convert to radians and return unitless
|
// If compatible with radians, convert to radians and return unitless
|
||||||
@ -26,7 +27,7 @@ fn to_radians(q: Quantity) -> Result<Quantity, ()> {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn eval_function(g: &Expression) -> Result<Option<Expression>, (LineLocation, DaisyError)> {
|
pub fn eval_function(context: &mut Context, g: &Expression) -> Result<Option<Expression>, (LineLocation, DaisyError)> {
|
||||||
|
|
||||||
let Expression::Operator(loc, Operator::Function(f), args) = g else {unreachable!()};
|
let Expression::Operator(loc, Operator::Function(f), args) = g else {unreachable!()};
|
||||||
|
|
||||||
@ -154,17 +155,51 @@ pub fn eval_function(g: &Expression) -> Result<Option<Expression>, (LineLocation
|
|||||||
Function::ToCelsius => {
|
Function::ToCelsius => {
|
||||||
let mut k = Quantity::new_rational(1f64).unwrap();
|
let mut k = Quantity::new_rational(1f64).unwrap();
|
||||||
k.insert_unit(FreeUnit::from_whole(WholeUnit::Kelvin), Scalar::new_rational(1f64).unwrap());
|
k.insert_unit(FreeUnit::from_whole(WholeUnit::Kelvin), Scalar::new_rational(1f64).unwrap());
|
||||||
let Some(q) = q.convert_to(k) else { return Err((*loc + *l, DaisyError::IncompatibleUnit)) };
|
|
||||||
|
let q_s: String;
|
||||||
|
if q.unitless() {
|
||||||
|
q_s = String::from("scalar");
|
||||||
|
} else {
|
||||||
|
q_s = q.convert_to_base().unit().display(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(q) = q.convert_to(k) else {
|
||||||
|
return Err((
|
||||||
|
*loc + *l,
|
||||||
|
DaisyError::IncompatibleUnits(
|
||||||
|
q_s,
|
||||||
|
Unit::from_free(FreeUnit::from_whole(WholeUnit::Kelvin)).display(context)
|
||||||
|
)
|
||||||
|
))
|
||||||
|
};
|
||||||
|
|
||||||
let mut r = q.without_unit();
|
let mut r = q.without_unit();
|
||||||
r += Quantity::new_rational(-273.15f64).unwrap();
|
r += Quantity::new_rational(-273.15f64).unwrap();
|
||||||
|
|
||||||
return Ok(Some(Expression::Quantity(*loc + *l, r)));
|
return Ok(Some(Expression::Quantity(*loc + *l, r)));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
Function::ToFahrenheit => {
|
Function::ToFahrenheit => {
|
||||||
let mut k = Quantity::new_rational(1f64).unwrap();
|
let mut k = Quantity::new_rational(1f64).unwrap();
|
||||||
k.insert_unit(FreeUnit::from_whole(WholeUnit::Kelvin), Scalar::new_rational(1f64).unwrap());
|
k.insert_unit(FreeUnit::from_whole(WholeUnit::Kelvin), Scalar::new_rational(1f64).unwrap());
|
||||||
let Some(q) = q.convert_to(k) else { return Err((*loc + *l, DaisyError::IncompatibleUnit)) };
|
|
||||||
|
let q_s: String;
|
||||||
|
if q.unitless() {
|
||||||
|
q_s = String::from("scalar");
|
||||||
|
} else {
|
||||||
|
q_s = q.convert_to_base().unit().display(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(q) = q.convert_to(k) else {
|
||||||
|
return Err((
|
||||||
|
*loc + *l,
|
||||||
|
DaisyError::IncompatibleUnits(
|
||||||
|
q_s,
|
||||||
|
Unit::from_free(FreeUnit::from_whole(WholeUnit::Kelvin)).display(context)
|
||||||
|
)
|
||||||
|
))
|
||||||
|
};
|
||||||
|
|
||||||
let mut r = q.without_unit();
|
let mut r = q.without_unit();
|
||||||
r *= Quantity::new_rational_from_frac(9i64, 5i64).unwrap();
|
r *= Quantity::new_rational_from_frac(9i64, 5i64).unwrap();
|
||||||
@ -173,8 +208,18 @@ pub fn eval_function(g: &Expression) -> Result<Option<Expression>, (LineLocation
|
|||||||
|
|
||||||
return Ok(Some(Expression::Quantity(*loc + *l, r)));
|
return Ok(Some(Expression::Quantity(*loc + *l, r)));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
Function::FromCelsius => {
|
Function::FromCelsius => {
|
||||||
if !q.unitless() { return Err((*loc + *l, DaisyError::IncompatibleUnit));}
|
if !q.unitless() {
|
||||||
|
return Err((
|
||||||
|
*loc + *l,
|
||||||
|
DaisyError::IncompatibleUnits(
|
||||||
|
q.convert_to_base().unit().display(context),
|
||||||
|
"scalar".to_string()
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let mut r = Quantity::new_rational(273.15f64).unwrap();
|
let mut r = Quantity::new_rational(273.15f64).unwrap();
|
||||||
r += q.clone();
|
r += q.clone();
|
||||||
@ -182,8 +227,18 @@ pub fn eval_function(g: &Expression) -> Result<Option<Expression>, (LineLocation
|
|||||||
|
|
||||||
return Ok(Some(Expression::Quantity(*loc + *l, r)));
|
return Ok(Some(Expression::Quantity(*loc + *l, r)));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
Function::FromFahrenheit => {
|
Function::FromFahrenheit => {
|
||||||
if !q.unitless() { return Err((*loc + *l, DaisyError::IncompatibleUnit));}
|
if !q.unitless() {
|
||||||
|
return Err((
|
||||||
|
*loc + *l,
|
||||||
|
DaisyError::IncompatibleUnits(
|
||||||
|
q.convert_to_base().unit().display(context),
|
||||||
|
"scalar".to_string()
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
let mut r = q.clone();
|
let mut r = q.clone();
|
||||||
r += Quantity::new_rational(459.67).unwrap();
|
r += Quantity::new_rational(459.67).unwrap();
|
||||||
|
@ -124,6 +124,8 @@ pub fn eval_operator(context: &mut Context, g: &Expression) -> Result<Option<Exp
|
|||||||
if let Expression::Quantity(la, a) = a {
|
if let Expression::Quantity(la, a) = a {
|
||||||
if let Expression::Quantity(lb, b) = b {
|
if let Expression::Quantity(lb, b) = b {
|
||||||
if !a.unit.compatible_with(&b.unit) {
|
if !a.unit.compatible_with(&b.unit) {
|
||||||
|
let a = a.convert_to_base().unit;
|
||||||
|
let b = b.convert_to_base().unit;
|
||||||
|
|
||||||
let a_s: String;
|
let a_s: String;
|
||||||
let b_s: String;
|
let b_s: String;
|
||||||
|
Reference in New Issue
Block a user