{"id":13413739,"url":"https://github.com/soniah/evaler","last_synced_at":"2025-10-04T10:32:24.856Z","repository":{"id":4539696,"uuid":"5680134","full_name":"soniah/evaler","owner":"soniah","description":"Implements a simple floating point arithmetic expression evaluator in Go (golang).","archived":false,"fork":false,"pushed_at":"2018-07-27T12:02:52.000Z","size":100,"stargazers_count":51,"open_issues_count":5,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T11:43:33.544Z","etag":null,"topics":["go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soniah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-04T23:37:58.000Z","updated_at":"2024-08-17T13:49:21.000Z","dependencies_parsed_at":"2022-09-18T20:52:10.319Z","dependency_job_id":null,"html_url":"https://github.com/soniah/evaler","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soniah%2Fevaler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soniah%2Fevaler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soniah%2Fevaler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soniah%2Fevaler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soniah","download_url":"https://codeload.github.com/soniah/evaler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248783388,"owners_count":21160913,"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":["go","golang"],"created_at":"2024-07-30T20:01:47.836Z","updated_at":"2025-10-04T10:32:15.103Z","avatar_url":"https://github.com/soniah.png","language":"Go","readme":"evaler\n======\n\n[![Build Status](https://travis-ci.org/soniah/evaler.svg?branch=master)](https://travis-ci.org/soniah/evaler)\n[![Coverage](http://gocover.io/_badge/github.com/soniah/evaler)](http://gocover.io/github.com/soniah/evaler)\n[![GoDoc](https://godoc.org/github.com/soniah/evaler?status.png)](http://godoc.org/github.com/soniah/evaler)\nhttps://github.com/soniah/evaler\n\nPackage evaler implements a simple floating point arithmetic expression evaluator.\n\nEvaler uses Dijkstra's [Shunting Yard algorithm](http://en.wikipedia.org/wiki/Shunting-yard_algorithm) to convert an\ninfix expression to [postfix/RPN format](http://en.wikipedia.org/wiki/Reverse_Polish_notation), then evaluates\nthe RPN expression. The implementation is adapted from a [Java implementation](http://willcode4beer.com/design.jsp?set=evalInfix). The results\nare returned as a `*big.Rat`.\n\nUsage\n-----\n\n```go\nresult, err := evaler.Eval(\"1+2\")\n```\n\nOperators\n---------\n\nThe operators supported are:\n\n```+ - * / ^ ** () \u003c \u003e \u003c= \u003e= == !=```\n\n(`^` and `**` are both exponent operators)\n\nLogical operators like `\u003c` (less than) or `\u003e` (greater than) get lowest precedence,\nall other precedence is as expected -\n[BODMAS](http://www.mathsisfun.com/operation-order-bodmas.html).\n\nLogical tests like `\u003c` and `\u003e` tests will evaluate to 0.0 for false and 1.0\nfor true, allowing expressions like:\n\n```\n3 * (1 \u003c 2) # returns 3.0\n3 * (1 \u003e 2) # returns 0.0\n```\n\nMinus implements both binary and unary operations.\n\nSee `evaler_test.go` for more examples of using operators.\n\nTrigonometric Operators\n-----------------------\n\nThe trigonometric operators supported are:\n\n```sin, cos, tan, ln, arcsin, arccos, arctan```\n\nFor example:\n\n```\ncos(1)\nsin(2-1)\nsin(1)+2**2\n```\n\nSee `evaler_test.go` for more examples of using trigonometric operators.\n\nVariables\n---------\n\n`EvalWithVariables()` allows variables to be passed into expressions,\nfor example evaluate `\"x + 1\"`, where `x=5`.\n\nSee `evaler_test.go` for more examples of using variables.\n\nIssues\n------\n\nThe `math/big` library doesn't have an exponent function `**` and implenting one\nfor `big.Rat` numbers is non-trivial. As a work around, arguments are converted\nto float64's, the calculation is done using the `math.Pow()` function, the\nresult is converted to a `big.Rat` and placed back on the stack.\n\n* floating point numbers missing leading digits (like `\".5 * 2\"`) are failing - PR's welcome\n\nDocumentation\n-------------\n\nhttp://godoc.org/github.com/soniah/evaler\n\nThere are also a number of utility functions e.g. `BigratToFloat()`,\n`BigratToInt()` that may be useful when working with evaler.\n\nContributions\n-------------\n\nContributions are welcome.\n\nIf you've never contributed to a Go project before here is an example workflow.\n\n1. [fork this repo on the GitHub webpage](https://github.com/soniah/evaler/fork)\n1. `go get github.com/soniah/evaler`\n1. `cd $GOPATH/src/github.com/soniah/evaler`\n1. `git remote rename origin upstream`\n1. `git remote add origin git@github.com:\u003cyour-github-username\u003e/evaler.git`\n1. `git checkout -b development`\n1. `git push -u origin development` (setup where you push to, check it works)\n\nAuthor\n------\n\nSonia Hamilton sonia@snowfrog.net\n\nDem Waffles dem-waffles@server.fake - trigonometric operators\n\nLicense\n-------\n\nModified BSD License (BSD-3)\n\nLinks\n-----\n\n[1] http://en.wikipedia.org/wiki/Shunting-yard_algorithm\n\n[2] http://en.wikipedia.org/wiki/Reverse_Polish_notation\n\n[3] http://willcode4beer.com/design.jsp?set=evalInfix\n\n[4] http://www.mathsisfun.com/operation-order-bodmas.html\n\n","funding_links":[],"categories":["Science and Data Analysis","数据分析与数据科学","科学与数据分析","科学及数据分析","科學及數據分析","\u003cspan id=\"科学和数据分析-science-and-data-analysis\"\u003e科学和数据分析 Science and Data Analysis\u003c/span\u003e","Relational Databases","科学和数据分析"],"sub_categories":["HTTP Clients","Advanced Console UIs","查询语","HTTP客户端","高级控制台界面","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoniah%2Fevaler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoniah%2Fevaler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoniah%2Fevaler/lists"}