Ejemplo n.º 1
0
func setupConstantExps() {
	standardFuncs["ln"] = pcalc.NaturalLogarithmOfExpression(pcalc.NewExpressionWithUnknown("a"))
	standardFuncs["lg"] = pcalc.DecimalLogarithmOfExpression(pcalc.NewExpressionWithUnknown("a"))

	chemicalConstants["R"] = pcalc.NewExpressionWithConstant(pcalc.MakeSDFloat(8.3144, 5))
	chemicalConstants["r"] = chemicalConstants["R"]
	chemicalConstants["F"] = pcalc.NewExpressionWithConstant(pcalc.MakeSDFloat(96485.33, 7))
	chemicalConstants["f"] = chemicalConstants["F"]

	physicalConstants["C"] = pcalc.NewExpressionWithConstant(pcalc.MakeSDFloat(299792458, 9))
	physicalConstants["c"] = physicalConstants["C"]
	physicalConstants["G"] = pcalc.NewExpressionWithConstant(pcalc.MakeSDFloat(9.80665, 6))
	physicalConstants["g"] = physicalConstants["G"]

	mathematicalConstants["pi"] = pcalc.NewExpressionWithConstant(pcalc.MakeSDFloat(math.Pi, 15))
	mathematicalConstants["e"] = pcalc.NewExpressionWithConstant(pcalc.MakeSDFloat(math.E, 15))
}
Ejemplo n.º 2
0
func parseUnknownExpressions(s string, starti int) []pElement {
	nextParseFunction := parseFloatExpressions
	ret := make([]pElement, 0)
	ind := unknownRE.FindStringIndex(s)
	if len(ind) == 0 {
		ret = nextParseFunction(s, starti)
	} else {
		if ind[0] > 0 {
			ret = append(ret, nextParseFunction(s[:ind[0]], starti)...)
		}
		if ind[0] < ind[1] {
			var exp *pcalc.Expression
			exp = pcalc.NewExpressionWithUnknown(s[ind[0]:ind[1]])
			ne := pElement{exp, [2]int{starti + ind[0], starti + ind[1]}}
			ret = append(ret, ne)
		}
		if ind[1] < len(s) {
			ret = append(ret, parseUnknownExpressions(s[ind[1]:], starti+ind[1])...)
		}
	}
	return ret
}