{"id":13822489,"url":"https://github.com/likebike/fasteval","last_synced_at":"2025-05-16T04:04:41.592Z","repository":{"id":36235413,"uuid":"214268896","full_name":"likebike/fasteval","owner":"likebike","description":"Fast and safe evaluation of algebraic expressions","archived":false,"fork":false,"pushed_at":"2023-11-10T20:51:52.000Z","size":661,"stargazers_count":286,"open_issues_count":19,"forks_count":31,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-09T20:06:25.937Z","etag":null,"topics":["algebra","algebraic-expressions","eval","math","rust","rust-lang"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/fasteval/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/likebike.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-10-10T19:30:42.000Z","updated_at":"2025-04-24T05:32:25.000Z","dependencies_parsed_at":"2023-12-27T00:22:37.778Z","dependency_job_id":"c4fae2bb-563c-41e0-ac32-2332a0bf9b82","html_url":"https://github.com/likebike/fasteval","commit_stats":{"total_commits":142,"total_committers":2,"mean_commits":71.0,"dds":0.007042253521126751,"last_synced_commit":"1e5154b4dca3d24575cf853ecfe36a5699e496fe"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/likebike%2Ffasteval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/likebike%2Ffasteval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/likebike%2Ffasteval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/likebike%2Ffasteval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/likebike","download_url":"https://codeload.github.com/likebike/fasteval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464894,"owners_count":22075570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algebra","algebraic-expressions","eval","math","rust","rust-lang"],"created_at":"2024-08-04T08:02:02.485Z","updated_at":"2025-05-16T04:04:40.583Z","avatar_url":"https://github.com/likebike.png","language":"Rust","readme":"# fasteval\nFast and safe evaluation of algebraic expressions\n\n`fasteval` is a library for parsing, compiling, and evaluating algebraic expressions.\nIt can be used directly as a calculator language (much like `python`), and it is\nan excellent foundation for building higher-level-languages.\n\nDocumentation:\n\n* [API Reference (docs.rs)](https://docs.rs/fasteval/)\n\n\n## Usage\n\nAdd this to your Cargo.toml:\n\n    [dependencies]\n    fasteval = \"0.2.4\"\n\n\nYou can use [`codegen-units=1`](https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-profile-sections) for better run-time performance. In some cases [it will greatly improves LLVM's compile-time optimizations](http://likebike.com/posts/How_To_Write_Fast_Rust_Code.html#emit-asm).\n\nIf you are using a 'nightly' Rust compiler, you can build with `--features nightly` to enable optimizations that aren't yet available in 'stable' Rust.\n\nYou can build with `--no-default-features` to disable alphabetical keywords like `and`, `or`, `NaN`, `inf`.  (These words might be important to your applications.)\n\nYou can build with `--features unsafe-vars` to enable [Unsafe Variables](https://docs.rs/fasteval/#unsafe-variables).\n\n\n## Features\n* No dependencies.\n* Safe execution of untrusted expressions.\n* Works with stable Rust.\n* Supports interpretation (i.e. parse \u0026 eval) as well as compiled execution (i.e. parse, compile, eval).\n* Supports Variables and Custom Functions.\n* `fasteval` is a good base for building higher-level languages.\n* Supports many built-in functions and constants.\n* Supports all the standard algebraic unary and binary operators (+ - * / ^ %),\n  as well as comparisons (\u003c \u003c= == != \u003e= \u003e) and logical operators (\u0026\u0026 ||) with\n  short-circuit support.\n* Easy integration into many different types of applications, including scoped evaluation.\n* Very fast performance.\n\n\n## Easy Example\n\nHere is one simple example.  See the [API Reference](https://docs.rs/fasteval/#examples) for many more!\n\nThe `ez_eval()` function performs the entire allocation-parse-eval process\nfor you.  It is slightly inefficient because it always allocates a\nfresh [`Slab`](https://docs.rs/fasteval/latest/fasteval/slab/index.html), but it is very simple to use:\n\n```rust\nfn main() -\u003e Result\u003c(), fasteval::Error\u003e {\n    // This example doesn't use any variables, so just use an EmptyNamespace:\n    let mut ns = fasteval::EmptyNamespace;\n\n    let val = fasteval::ez_eval(\n        \"1+2*3/4^5%6 + log(100K) + log(e(),100) + [3*(3-3)/3] + (2\u003c3) \u0026\u0026 1.23\",    \u0026mut ns)?;\n    //    |            |      |    |   |          |               |   |\n    //    |            |      |    |   |          |               |   boolean logic with short-circuit support\n    //    |            |      |    |   |          |               comparisons\n    //    |            |      |    |   |          square-brackets act like parenthesis\n    //    |            |      |    |   built-in constants: e(), pi()\n    //    |            |      |    'log' can take an optional first 'base' argument, defaults to 10\n    //    |            |      numeric literal with suffix: p, n, µ, m, K, M, G, T\n    //    |            many built-in functions: print, int, ceil, floor, abs, sign, log, round, min, max, sin, asin, ...\n    //    standard binary operators\n\n    assert_eq!(val, 1.23);\n\n    Ok(())\n}\n```\n\n\n## REPL Demo\n```text\ngithub.com/likebike/fasteval$ rlwrap cargo run --release --example repl\n    Finished release [optimized] target(s) in 0.01s\n     Running `target/release/examples/repl`\n\u003e\u003e\u003e print(\"Hello fasteval\", 1, 2, 3)\nHello fasteval 1 2 3\n3\n\u003e\u003e\u003e _ + 1\n4\n\u003e\u003e\u003e _ + 1\n5\n\u003e\u003e\u003e _ * 2\n10\n\u003e\u003e\u003e _ ^ 0.5\n3.1622776601683795\n\u003e\u003e\u003e let a = 1\n1\n\u003e\u003e\u003e let b = a + 1\n2\n\u003e\u003e\u003e let c = a + b * 3\n7\n\u003e\u003e\u003e a + b + c\n10\n\u003e\u003e\u003e push\nEntered scope[1]\n\u003e\u003e\u003e let b = b + 10\n12\n\u003e\u003e\u003e a + b + c\n20\n\u003e\u003e\u003e pop\nExited scope[1]\n\u003e\u003e\u003e a + b + c\n10\n\u003e\u003e\u003e 1+2*3/4^5%6 + log(100K) + log(e(),100) + [3*(3-3)/3] + (2\u003c3) \u0026\u0026 1.23\n1.23\n\u003e\u003e\u003e 1+2*3/4^5%6 + print(\"log(100K) =\",log(100K)) + log(e(),100) + [3*(3-3)/3] + (2\u003c3) \u0026\u0026 1.23\nlog(100K) = 5\n1.23\n```\n\n## Safety\n\n`fasteval` is designed to evaluate untrusted expressions safely.  By\ndefault, an expression can only perform math operations; there is no way\nfor it to access other types of operations (like network or filesystem or\nexternal commands).  Additionally, we guard against malicious expressions:\n\n* Expressions that are too large (greater than 4KB).\n* Expressions that are too-deeply nested (greater than 32 levels).\n* Expressions with too many values (greater than 64).\n* Expressions with too many sub-expressions (greater than 64).\n\nAll limits can be customized at parse time.  If any limits are exceeded,\n[`parse()`](https://docs.rs/fasteval/latest/fasteval/parser/struct.Parser.html#method.parse) will return an\n[Error](https://docs.rs/fasteval/latest/fasteval/error/enum.Error.html).\n\nNote that it *is* possible for you (the developer) to define custom functions\nwhich might perform dangerous operations.  It is your responsibility to make\nsure that all custom functionality is safe.\n\n\n## Performance Benchmarks\n\nHere is a short summary of the performance benchmarks.  For a more complete report and anlysis, see the [official documentation](https://docs.rs/fasteval/#performance-benchmarks).\n\n### Charts\nNote that the following charts use logarithmic scales.  Therefore, tiny\nvisual differences actually represent very significant performance\ndifferences.\n\n**Performance of evaluation of a compiled expression:**  \n![Compiled Eval Performance](https://raw.githubusercontent.com/likebike/fasteval/master/benches/results/20191225/fasteval-compiled.png)\n\n**Performance of one-time interpretation (parse and eval):**  \n![Interpretation Performance](https://raw.githubusercontent.com/likebike/fasteval/master/benches/results/20191225/fasteval-interp.png)\n\n**Performance of compiled Unsafe Variables, compared to the tinyexpr C library (the\nonly other library in our test set that supports this mode):**  \n![Unsafe Compiled Eval Performance](https://raw.githubusercontent.com/likebike/fasteval/master/benches/results/20191225/fasteval-compiled-unsafe.png)\n\n**Performance of interpreted Unsafe Variables, compared to the tinyexpr C library (the\nonly other library in our test set that supports this mode):**  \n![Unsafe Interpretation Performance](https://raw.githubusercontent.com/likebike/fasteval/master/benches/results/20191225/fasteval-interp-unsafe.png)\n\n### Summary\n\nThe impressive thing about these results is that `fasteval` consistently\nachieves the fastest times across every benchmark and in every mode of\noperation (interpreted, compiled, and unsafe).  It's easy to create a\ndesign to claim the #1 spot in any one of these metrics by sacrificing\nperformance in another, but it is difficult to create a design that can be\n#1 across-the-board.\n\nBecause of the broad and robust performance advantages, `fasteval` is very\nlikely to be an excellent choice for your dynamic evaluation needs.\n\n\n## License\n`fasteval` is distributed under the terms the MIT license.\n\nSee [LICENSE](https://github.com/likebike/fasteval/blob/master/LICENSE) for details.\n\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flikebike%2Ffasteval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flikebike%2Ffasteval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flikebike%2Ffasteval/lists"}