aboutsummaryrefslogtreecommitdiffstats
path: root/const.go
blob: 3808e820240a2cc99e6b0529f1eb8beeac634bce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package main

import "math"

func parseConstant(s string) (float64, error) {
	switch s {
	case "pi":
		return math.Pi, nil
	case "e":
		return math.E, nil
	}
	return 0, InvalidConstantErr{s}
}

type InvalidConstantErr struct {
	s string
}

func (e InvalidConstantErr) Error() string {
	return "invalid constant: " + e.s
}