{"id":15018682,"url":"https://github.com/muqsit/arithmexp","last_synced_at":"2025-10-30T09:37:35.325Z","repository":{"id":60036998,"uuid":"391817412","full_name":"Muqsit/arithmexp","owner":"Muqsit","description":"A powerful mathematical expression parser and evaluator for PHP featuring variable substitution, user-defined constants, functions, deterministic functions, macros, operators, and compiler optimizations.","archived":false,"fork":false,"pushed_at":"2024-07-12T18:17:15.000Z","size":406,"stargazers_count":26,"open_issues_count":4,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-30T20:51:49.668Z","etag":null,"topics":["calculator","compiler","composer-library","constant-folding","logic","math","mathematical-expression-parser","optimization","parser","php","phpstan-l9","pmmp","pocketmine-mp","strength-reduction","virion"],"latest_commit_sha":null,"homepage":"https://arithmexp.pages.dev","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Muqsit.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-02T04:42:16.000Z","updated_at":"2024-12-18T09:23:58.000Z","dependencies_parsed_at":"2024-09-24T21:02:01.109Z","dependency_job_id":null,"html_url":"https://github.com/Muqsit/arithmexp","commit_stats":{"total_commits":409,"total_committers":4,"mean_commits":102.25,"dds":0.0488997555012225,"last_synced_commit":"73fe866fa26cf8605073d56363e2ec0074d9769d"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2Farithmexp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2Farithmexp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2Farithmexp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Muqsit%2Farithmexp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Muqsit","download_url":"https://codeload.github.com/Muqsit/arithmexp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237882172,"owners_count":19381176,"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":["calculator","compiler","composer-library","constant-folding","logic","math","mathematical-expression-parser","optimization","parser","php","phpstan-l9","pmmp","pocketmine-mp","strength-reduction","virion"],"created_at":"2024-09-24T19:52:16.630Z","updated_at":"2025-10-30T09:37:35.252Z","avatar_url":"https://github.com/Muqsit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# arithmexp\n[![CI](https://github.com/Muqsit/arithmexp/actions/workflows/ci.yml/badge.svg)](https://github.com/Muqsit/arithmexp/actions/workflows/ci.yml)\n[![Latest Release](https://img.shields.io/github/v/release/Muqsit/arithmexp)](https://github.com/Muqsit/arithmexp/releases/latest)\n\n[`arithmexp`](https://github.com/Muqsit/arithmexp) is a powerful mathematical expression parser and evaluator library for PHP with support for [variable substitution](https://github.com/Muqsit/arithmexp#evaluating-a-mathematical-expression), [constant declaration](https://github.com/Muqsit/arithmexp/wiki), [deterministic and non-deterministic function registration](https://github.com/Muqsit/arithmexp/wiki), and more.\n\n\u003e [!TIP]\n\u003e Try out arithmexp parser on the [**demo site**](https://arithmexp.pages.dev/)!\n\n## Installation with composer\n```\ncomposer require muqsit/arithmexp\n```\n\n## Evaluating a mathematical expression\nTo evaluate a mathematical expression, create a [`Parser`](https://github.com/Muqsit/arithmexp/blob/master/src/muqsit/arithmexp/Parser.php) and invoke `Parser::parse()` with an expression string to obtain a reusable [`Expression`](https://github.com/Muqsit/arithmexp/blob/master/src/muqsit/arithmexp/expression/Expression.php) object.\n`Expression::evaluate()` returns the value of the expression.\n```php\n$parser = Parser::createDefault();\n$expression = $parser-\u003eparse(\"2 + 3\");\nvar_dump($expression-\u003eevaluate()); // int(5)\n\n$expression = $parser-\u003eparse(\"mt_rand()\");\nvar_dump($expression-\u003eevaluate()); // int(1370501507)\nvar_dump($expression-\u003eevaluate()); // int(1522981420)\n```\n\nVariables may be substituted at evaluation-time by passing an `array\u003cstring, int|float|bool\u003e` value to `Expression::evaluate()`.\n```php\n$expression = $parser-\u003eparse(\"x + y\");\nvar_dump($expression-\u003eevaluate([\"x\" =\u003e 2, \"y\" =\u003e 3])); // int(5)\nvar_dump($expression-\u003eevaluate([\"x\" =\u003e 1.5, \"y\" =\u003e 1.5])); // float(3)\n\n$expression = $parser-\u003eparse(\"a \u003e b or c\");\nvar_dump($expression-\u003eevaluate([\"a\" =\u003e 1, \"b\" =\u003e 2, \"c\" =\u003e true])); // bool(true)\n```\nThe return value type of the evaluation is consistent with that of PHP's—`int + int` returns an `int` value, while `float + int|float` returns a `float` value.\n`bool + bool` returns an `int` value, while `int || int` returns a `bool` value.\n\n\u003e [!NOTE]\n\u003e Check out the [**wiki**](https://github.com/Muqsit/arithmexp/wiki) for documentation notes and further implementation details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuqsit%2Farithmexp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuqsit%2Farithmexp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuqsit%2Farithmexp/lists"}