![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
github.com/darenliang/go-math-eval
A simple math expression evaluator written in Go using Shunting Yard and Reverse Polish.
To install:
go get github.com/darenliang/gomatheval
Evaluating expressions
package main
import (
"fmt"
"github.com/darenliang/gomatheval"
"math"
)
func main() {
fmt.Println(gomatheval.EvalExpression(fmt.Sprintf("-(3+(sin(%v/2))^2)/4", math.Pi)))
// outputs 1
}
Command-Line Application
package main
import (
"flag"
"fmt"
"github.com/darenliang/gomatheval"
)
func main() {
optionPtr := flag.String("op", "e", "Select processing option.\n" +
"e: Evaluate expression\n" +
"p: Process to Reverse Polish Notation\n" +
"t: Tokenize expression\n")
expressionPtr := flag.String("exp", "", "Expression string to be processed")
flag.Parse()
switch *optionPtr {
case "t":
fmt.Println(gomatheval.SanitizeExpression(*expressionPtr))
case "p":
fmt.Println(gomatheval.ParseRPN(gomatheval.SanitizeExpression(*expressionPtr)))
default:
fmt.Println(gomatheval.EvalExpression(*expressionPtr))
}
}
+ (addition)
, - (subtraction)
, * (multiplication)
, / (division)
, % (modulo)
, ^ (power)
.sin (sine)
, cos (cosine)
, tan (tangent)
, ln (natural logarithm)
, lg (base 2 logarithm)
, log (logarithm with variable base)
. More operators coming soon...Every expression is composed of three kinds of tokens:
By tokenizing an expression, we can get the individual elements that make up the expression:
-(3+(sin(3.141592653589793/2))^2)/4
=> - ( 3 + ( sin ( 3.141592653589793 / 2 ) ) ^ 2 ) / 4
The tokenized expression is then sanitized and unary operators are converted to unique operators.
- ( 3 + ( sin ( 3.141592653589793 / 2 ) ) ^ 2 ) / 4
=> -u ( 3 + ( sin ( 3.141592653589793 / 2 ) ) ^ 2 ) / 4
By using the Shunting Yard Algorithm we can convert this infix notation into postfix notation (also known as Reverse Polish notation).
-u ( 3 + ( sin ( 3.141592653589793 / 2 ) ) ^ 2 ) / 4
=> 3 3.141592653589793 2 / sin 2 ^ + -u 4 /
By evaluating the postfix notation tokens, we can obtain a final value.
3 3.141592653589793 2 / sin 2 ^ + -u 4 /
=> -1
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.