|
1 | | -# Modern C++ Calculator |
| 1 | +# Modern C++ Calculator v2.1 |
2 | 2 |
|
3 | 3 | [](https://github.com/ElementAstro/calculator/actions/workflows/codeql.yml) |
4 | 4 | [](https://github.com/ElementAstro/calculator/actions/workflows/windows-mingw.yml) |
5 | 5 | [](https://sonarcloud.io/summary/new_code?id=ElementAstro_calculator) |
6 | 6 | [](https://elementastro.github.io/calculator/) |
7 | 7 |
|
8 | | -A modern, high-performance C++ header-only calculator library for evaluating mathematical expressions. Built with C++17/20 features, this library provides a robust and flexible expression parser that supports variables, functions, and comprehensive mathematical operations. |
| 8 | +A modern, high-performance C++ header-only calculator library for evaluating mathematical expressions. Built with C++17/20 features, this library provides a robust and flexible expression parser that supports variables, functions, comparison/logical operators, conditional expressions, complex numbers, symbolic differentiation, and a REPL interface. |
9 | 9 |
|
10 | 10 | 📖 **[Complete Documentation](https://elementastro.github.io/calculator/)** | 🚀 **[Quick Start Guide](https://elementastro.github.io/calculator/getting-started/quick-start/)** | 📋 **[API Reference](https://elementastro.github.io/calculator/api-reference/)** |
11 | 11 |
|
12 | 12 | ## ✨ Key Features |
13 | 13 |
|
14 | | -- **🚀 Header-only**: Single file, easy integration |
15 | | -- **🔢 Multiple numeric types**: Support for `int`, `float`, and `double` |
| 14 | +- **🚀 Header-only**: Modular design, easy integration |
| 15 | +- **🔢 Multiple numeric types**: Support for `int`, `float`, `double`, and `std::complex<double>` |
16 | 16 | - **⚡ High performance**: Optimized expression parsing and evaluation |
17 | | -- **🧮 Comprehensive operations**: Arithmetic, bitwise, and exponentiation |
18 | | -- **📐 Mathematical functions**: Support for custom functions and variables |
| 17 | +- **🧮 Comprehensive operations**: Arithmetic, bitwise, comparison, logical, and power operations |
| 18 | +- **📐 Mathematical functions**: 60+ built-in functions (trigonometric, hyperbolic, combinatorics, etc.) |
| 19 | +- **🔀 Conditional expressions**: Ternary operator support (`condition ? true : false`) |
| 20 | +- **📝 User-defined functions**: Define custom functions like `f(x) = x^2 + 2*x + 1` |
| 21 | +- **🔣 Complex numbers**: Full complex number arithmetic support |
| 22 | +- **📊 Symbolic differentiation**: Compute derivatives symbolically |
| 23 | +- **💻 REPL interface**: Interactive calculator with history support |
19 | 24 | - **🛡️ Robust error handling**: Detailed error messages with position information |
20 | 25 | - **📏 Operator precedence**: Follows standard mathematical precedence rules |
21 | 26 | - **🔧 Template-based**: Type-safe generic implementation |
| 27 | +- **🔬 Physics constants**: Built-in physical constants (c, G, h, Na, etc.) |
22 | 28 |
|
23 | 29 | ## 🚀 Quick Start |
24 | 30 |
|
@@ -60,17 +66,48 @@ int main() { |
60 | 66 | | Category | Operators | Example | Types | |
61 | 67 | |----------|-----------|---------|-------| |
62 | 68 | | **Arithmetic** | `+`, `-`, `*`, `/`, `%` | `3 + 4 * 2` | All | |
63 | | -| **Bitwise** | `\|`, `^`, `&`, `<<`, `>>`, `~` | `5 & 3` | `int` only | |
64 | | -| **Exponentiation** | `**`, `e`/`E` | `2 ** 3`, `1.5e2` | All | |
65 | | -| **Unary** | `+`, `-`, `~` | `+5`, `-3`, `~7` | All/`int` | |
| 69 | +| **Floor Division** | `//` | `7 // 3` → `2` | All | |
| 70 | +| **Power** | `^`, `**` | `2^3`, `2**3` | All | |
| 71 | +| **Comparison** | `>`, `<`, `>=`, `<=`, `==`, `!=` | `5 > 3` | All | |
| 72 | +| **Logical** | `&&`, `\|\|`, `!` | `(5>3) && (2<4)` | All | |
| 73 | +| **Bitwise** | `&`, `\|`, `~`, `<<`, `>>` | `5 & 3` | `int` only | |
| 74 | +| **Conditional** | `? :` | `x > 0 ? x : -x` | All | |
| 75 | +| **Assignment** | `=` | `x = 10` | All | |
66 | 76 | | **Grouping** | `(`, `)` | `(2 + 3) * 4` | All | |
67 | 77 |
|
| 78 | +### Built-in Functions |
| 79 | + |
| 80 | +| Category | Functions | |
| 81 | +|----------|-----------| |
| 82 | +| **Trigonometric** | `sin`, `cos`, `tan`, `cot`, `sec`, `csc` | |
| 83 | +| **Inverse Trig** | `asin`, `acos`, `atan`, `acot`, `asec`, `acsc` | |
| 84 | +| **Hyperbolic** | `sinh`, `cosh`, `tanh`, `coth`, `sech`, `csch` | |
| 85 | +| **Inverse Hyperbolic** | `asinh`, `acosh`, `atanh` | |
| 86 | +| **Logarithmic** | `log`, `log10`, `log2`, `ln`, `exp`, `exp2`, `expm1`, `log1p` | |
| 87 | +| **Power/Root** | `sqrt`, `cbrt`, `sqr`, `cube`, `pow(x,y)`, `hypot(x,y)` | |
| 88 | +| **Rounding** | `floor`, `ceil`, `round`, `trunc`, `frac`, `abs` | |
| 89 | +| **Factorial/Gamma** | `fact`, `factorial`, `gamma`, `lgamma` | |
| 90 | +| **Combinatorics** | `nCr(n,r)`, `nPr(n,r)`, `comb`, `perm` | |
| 91 | +| **Number Theory** | `gcd(a,b)`, `lcm(a,b)` | |
| 92 | +| **Error Functions** | `erf`, `erfc` | |
| 93 | +| **Utility** | `sign`, `heaviside`, `recip`, `inv`, `deg`, `rad` | |
| 94 | +| **Two-Argument** | `max`, `min`, `mod`, `atan2`, `logb`, `avg`, `clamp`, `wrap` | |
| 95 | + |
| 96 | +### Built-in Constants |
| 97 | + |
| 98 | +| Category | Constants | |
| 99 | +|----------|-----------| |
| 100 | +| **Mathematical** | `pi`, `e`, `phi` (golden ratio), `tau` (2π), `sqrt2`, `sqrt3`, `ln2`, `ln10` | |
| 101 | +| **Special** | `inf` (infinity), `nan` (not a number) | |
| 102 | +| **Physics (SI)** | `c` (speed of light), `G` (gravitational), `h` (Planck), `kb` (Boltzmann), `Na` (Avogadro), `qe` (elementary charge) | |
| 103 | + |
68 | 104 | ### Advanced Features |
69 | 105 |
|
70 | | -- **Variables**: `parser.set("x", 5.0)` → `"x + 10"` |
71 | | -- **Functions**: `parser.set("sqrt", [](double x) { return std::sqrt(x); })` → `"sqrt(16)"` |
72 | | -- **Multiple Types**: `int`, `float`, `double` with type-specific behaviors |
73 | | -- **Error Handling**: Detailed error messages with position information |
| 106 | +- **Variables**: `x = 10` then use `x + 5` |
| 107 | +- **User-defined functions**: `f(x) = x^2 + 2*x + 1` then call `f(3)` |
| 108 | +- **Complex numbers**: `(3 + 4*i) * (1 + 2*i)` with `std::complex<double>` |
| 109 | +- **Symbolic differentiation**: `parser.diff("x^2", "x")` returns `"2 * x"` |
| 110 | +- **REPL interface**: Interactive calculator with command history |
74 | 111 |
|
75 | 112 | **[📋 Complete operator reference and examples →](https://elementastro.github.io/calculator/reference/operators/)** |
76 | 113 |
|
|
0 commit comments