Skip to content

Commit

Permalink
Implemented fractional exponentiation
Browse files Browse the repository at this point in the history
  • Loading branch information
bytesized committed Nov 28, 2024
1 parent be3f2d8 commit e9b028d
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 52 deletions.
31 changes: 14 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ repository = "https://github.com/bytesized/utilities"
[dependencies]
clap = { version = "4.0.29", features = ["derive"] }
crossterm = "0.25.0"
num = "0.4.0"
num = "0.4.2"
rusqlite = { version = "0.28.0", features = ["bundled"] }
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A command line calculator

In addition to allowing numbers to be arbitrarily large, bcalc stores non-integers via ratios rather than as floating point binary numbers. This means that precision isn't lost when binary floating point representations can't accurately represent a value. See [this Wikipedia article](https://en.wikipedia.org/wiki/Binary_number#Fractions) for more information on this problem.

Note that this approach can't really be used for irrational numbers. This isn't a problem for currently implemented features, but planned future features will be able to result in irrational numbers such as the square root of 2. The current plan is to use some sort of approximation in the case of irrational numbers.
Note that this approach can't really be used for irrational numbers. Operations that result in irrational numbers such as `sqrt 2` will use the configurable precision values to determine how many digits of precision to calculate. See `/help precision` for more details.

### Input History

Expand All @@ -25,7 +25,7 @@ Variables can then be used in the place of numbers in later expressions.

### Multisession support

bcalc can remember the input and variable history from previous sessions. This feature currently won't work properly, however, unless the environment is set up properly. This set up is performed automatically when via the installer for my [utilities](https://github.com/bytesized/utilities).
bcalc can remember the input and variable history from previous sessions. This feature currently won't work properly, however, unless the environment is set up properly. This set up is performed automatically when installed via [my utilities](https://github.com/bytesized/utilities) installer.

### Commands

Expand All @@ -36,6 +36,10 @@ bcalc has support for several commands which are invoked by beginning the calcul
/help help
```

### Consistent exit key

Control+D exits on all operating system including when using `-a`.

### Hotkeys

bcalc supports several navigation hotkeys:
Expand All @@ -47,5 +51,11 @@ bcalc supports several navigation hotkeys:

This project is still a work in progress. A number of features are planned or do not yet work properly:

- Fractional exponents
- The square root operator `sqrt`
- Fix navigation hotkeys. They don't seem to be working right, at least on macOS.
- Allow argument configuration values to be saved.
- Enable more detailed errors that point at the location of the error in the input.
- Add a `/quit` command.
- Add logarithm support.
- Add common constants such as pi.
- Add trigonometric functions.
- Support for imaginary numbers.
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub enum MathExecutionError {
UnknownVariable(String),
DivisionByZero,
FunctionNeedsArguments(FunctionNameToken),
Unimplemented,
ImaginaryResult,
}

impl fmt::Display for MathExecutionError {
Expand All @@ -181,8 +181,8 @@ impl fmt::Display for MathExecutionError {
MathExecutionError::FunctionNeedsArguments(function) => {
write!(f, "{} has no arguments but requires them", function)
}
MathExecutionError::Unimplemented => {
write!(f, "Encountered operation that is not yet supported")
MathExecutionError::ImaginaryResult => {
write!(f, "Unable to take the root of a negative number except unless the degree is an odd integer")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ fn calculate(
}

let st = SyntaxTree::new(tokens.into())?;
let result = st.execute(maybe_input_history_id, maybe_vars, maybe_db)?;
let result = st.execute(maybe_input_history_id, maybe_vars, maybe_db, args)?;

if args.fractional {
Ok(result.to_string())
Expand Down
Loading

0 comments on commit e9b028d

Please sign in to comment.