Skip to content

Commit

Permalink
Prepare to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadiguibou committed Oct 14, 2022
1 parent b67945c commit 2e1e8ad
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
name = "qalqulator"
version = "0.1.0"
edition = "2021"
license = "AGPL-3.0-or-later"
description = "A calculator that uses (and outputs) rational numbers wherever possible."
documentation = "https://docs.rs/qalqulator"
repository = "https://github.com/Gadiguibou/qalqulator/"
readme = "README.md"
keywords = ["calculator", "command-line", "arbitrary-precision", "rational-numbers"]
categories = ["command-line-utilities", "mathematics"]


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ A calculator that uses (and outputs) rational numbers wherever possible.

The only operation that causes the output to revert to a floating point is exponentiation with fractional exponents.

## Installation

### Using Cargo

1. Install [Rust](https://www.rust-lang.org/tools/install).
2. Run the following command in your terminal:

```bash
cargo install qalqulator
```

### Using pre-built binaries

Pre-built binaries are available on the [releases page](https://github.com/Gadiguibou/qalqulator/releases/).

## Example usage

```bash
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
pub mod parser;
use ast::Ast;
use eval::eval;
use parser::Parser;
use parser::Rule;
use pest::Parser as PestParser;

pub mod ast;
pub mod rational;
pub mod eval;
pub mod parser;
pub mod rational;

pub fn run(line: &str, env: &mut eval::Env) -> anyhow::Result<eval::Number> {
let parse = Parser::parse(Rule::line, line)?;
let ast = Ast::from_line(parse);
eval(ast, env)
}
11 changes: 1 addition & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use directories::BaseDirs;
use pest::Parser as PestParser;
use qalqulator::ast::Ast;
use qalqulator::eval::{eval, Env, Number};
use qalqulator::parser::{Parser, Rule};
use qalqulator::run;
use rustyline::error::ReadlineError;
use rustyline::Config;
use std::collections::HashMap;
Expand Down Expand Up @@ -51,9 +48,3 @@ fn main() -> anyhow::Result<()> {

Ok(())
}

fn run(line: &str, env: &mut Env) -> anyhow::Result<Number> {
let parse = Parser::parse(Rule::line, line)?;
let ast = Ast::from_line(parse);
eval(ast, env)
}
8 changes: 7 additions & 1 deletion src/rational.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct Rational {
numerator: i128,
denominator: i128,
Expand Down Expand Up @@ -39,6 +39,12 @@ impl Rational {
}
}

impl From<Rational> for f64 {
fn from(rational: Rational) -> f64 {
rational.to_f64()
}
}

impl std::fmt::Display for Rational {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if self.denominator != 1 {
Expand Down

0 comments on commit 2e1e8ad

Please sign in to comment.