mathypad_core/
lib.rs

1//! Mathypad Core - Shared calculation and parsing logic
2//!
3//! This crate contains the core mathematical evaluation, unit conversion,
4//! and expression parsing logic that is shared between the TUI and web UI versions of Mathypad.
5
6pub mod core;
7pub mod expression;
8pub mod units;
9
10// Constants used throughout the application
11pub const MAX_INTEGER_FOR_FORMATTING: f64 = 1e15;
12pub const FLOAT_EPSILON: f64 = f64::EPSILON;
13
14// Re-export commonly used types for convenience
15pub use expression::{
16    evaluator::{evaluate_expression_with_context, evaluate_with_variables},
17    parser::*,
18};
19pub use units::{Unit, UnitType, UnitValue, parse_unit};
20
21/// Test helpers for expression evaluation - shared across implementations
22pub mod test_helpers {
23    use crate::expression::evaluator::evaluate_expression_with_context;
24    use crate::units::UnitValue;
25
26    pub fn evaluate_test_expression(expr: &str) -> Option<String> {
27        evaluate_expression_with_context(expr, &[], 0)
28    }
29
30    pub fn evaluate_with_unit_info(expr: &str) -> Option<UnitValue> {
31        if let Some(result_str) = evaluate_expression_with_context(expr, &[], 0) {
32            crate::expression::evaluator::parse_result_string(&result_str)
33        } else {
34            None
35        }
36    }
37}