#rpn #computation #evaluation #calculator #reverse-polish-notation

squiid-engine

Squiid Engine is an RPN mathematical engine written in Rust

3 stable releases

Uses new Rust 2024

new 2.2.2 Mar 12, 2025
2.2.0 Mar 11, 2025

#244 in Math

39 downloads per month

GPL-3.0 license

140KB
1.5K SLoC

Squiid Engine

Squiid Engine is the core computational engine for Squiid Calculator, designed for efficient and precise mathematical computations using Reverse Polish Notation (RPN). It is implemented in Rust to ensure high performance and safety.

This library serves as the backend for Squiid Calculator, handling all mathematical operations, stack management, and evaluation logic. While Squiid Engine natively operates on RPN expressions, it can be paired with squiid-parser for converting algebraic expressions into RPN.

Features

  • Fast and memory-safe RPN evaluation
  • Well-documented API
  • Error handling with the prohibition of unwrap()/expect()
  • Able to be used through a variety of different languages through the bindings

Installation

cargo add squiid-engine

Example Usage

use squiid_engine::{execute_multiple_rpn, get_stack};

fn main() {
    // Execute an RPN expression: 3 + (5 * 7)
    let result = execute_multiple_rpn(vec!["3", "5", "7", "multiply", "add"]);

    assert!(result.get_error().is_none());

    let stack = get_stack();
    assert_eq!(stack[0].value.unwrap(), "38");

}

License

Squiid Engine is licensed under GPLv3.

Compiling

To compile the shared object file for use in bindings, just run install Rust and run cargo build --release --lib --features=ffi. The shared object file should be found in target/release/libsquiid_engine.so.

Dependencies

~3–12MB
~122K SLoC