{"id":26368768,"url":"https://github.com/bindreams/calc","last_synced_at":"2025-03-16T22:49:00.256Z","repository":{"id":167685044,"uuid":"398702854","full_name":"bindreams/calc","owner":"bindreams","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-07T15:25:54.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-07T16:27:47.671Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bindreams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2021-08-22T03:10:17.000Z","updated_at":"2025-03-07T15:25:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"67a4ab5c-8975-4790-a217-6bf631b84461","html_url":"https://github.com/bindreams/calc","commit_stats":null,"previous_names":["andreasxp/calc","bindreams/calc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fcalc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fcalc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fcalc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bindreams%2Fcalc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bindreams","download_url":"https://codeload.github.com/bindreams/calc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243945479,"owners_count":20372894,"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":[],"created_at":"2025-03-16T22:48:59.796Z","updated_at":"2025-03-16T22:49:00.238Z","avatar_url":"https://github.com/bindreams.png","language":"Python","readme":"# Calc\nEvaluate simple mathematical expressions.\n\n## Installation\nCalc is not available on PyPI, but can directly installed like this:\n```\npip install https://github.com/andreasxp/calc/archive/refs/heads/main.zip\n```\n\n## Examples\n```python\n    \u003e\u003e\u003e calc(\"2 + 2\")\n    4\n    \u003e\u003e\u003e calc(\"x^3\", {\"x\": 1.25})\n    1.953125\n    \u003e\u003e\u003e import math\n    \u003e\u003e\u003e calc(\"sin(pi/2)\", {\n    ...     \"sin\": math.sin,\n    ...     \"pi\": math.pi\n    ... })\n    1.0\n```\n\n## Usage\nThe main interface to this module is the `calc` function. Somewhat like `eval`, you can pass a string containing a\nmathematical expression to evaluate. Unlike `builtins.eval`, `calc` is completely safe - it supports only the\noperators, variables and functions you specify, and is confined to a simple set of grammar rules.\n\nKnown variables and functions can be added in the `identifiers` parameter. Additionally, you can specify custom unary\nand binary operators.  \n`identifiers`: a dict with entries `{name: function or variable}` -\n    function or variable name, matched to the actual function to call or a value.  \n`unary_operators`: a dict with entries `{(token, \"prefix\"/\"postfix\"): function}` -\n    a prefix/postfix token (`!`, `-`, `+`, `~`, etc.) mapped to a function taking one argument.\n    Postfix operators are executed before prefix operators.  \n`binary_operators`: a dict with entries `{(token, precedence[, \"lr\"/\"rl\"]): function}` -\n    a token with a precedence controlling order of operations (lower number is higher precedence),\n    optionally with right-to-left or left-to-right order of operations specified. For example,\n    power operator `^` would be right-to-left and highest precedence, so it could be specified as\n    `(\"^\", 1, \"rl\"): lambda x, y: x**y`.\n\n\nAn example of these parameters can be imported from this module:\n```python\ndefault_unary_operators = {\n    (\"-\", \"prefix\"): lambda x: -x,\n    (\"+\", \"prefix\"): lambda x: x\n}\n\ndefault_binary_operators = {\n    (\"+\", 3): operator.add,\n    (\"-\", 3): operator.sub,\n    (\"*\", 2): operator.mul,\n    (\"/\", 2): operator.truediv,\n    (\"%\", 2): math.remainder,\n    (\"^\", 1, \"rl\"): operator.pow,\n}\n\ndefault_identifiers = {\n    \"min\": min,\n    \"max\": max,\n    \"floor\": math.floor,\n    \"ceil\": math.ceil,\n    \"round\": round,\n    \"clamp\": lambda val, low, high: min(max(low, val), high),\n    \"sin\": math.sin,\n    \"cos\": math.cos,\n    \"tan\": math.tan,\n    \"asin\": math.asin,\n    \"acos\": math.acos,\n    \"atan\": math.atan,\n    \"atan2\": math.atan2,\n}\n```\n\nIf you need to customize the set of operators, but don't change them afterwards, it may be more efficient to create a\n`Evaluator(unary_operators, binary_operators)` instance, and use `evaluator.calc(identifiers)` instead of module-level `calc`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbindreams%2Fcalc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbindreams%2Fcalc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbindreams%2Fcalc/lists"}