aboutsummaryrefslogtreecommitdiffstats
path: root/const.go
diff options
context:
space:
mode:
Diffstat (limited to 'const.go')
-rw-r--r--const.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/const.go b/const.go
index ff0d09c..3808e82 100644
--- a/const.go
+++ b/const.go
@@ -2,16 +2,20 @@ package main
import "math"
-// parseConstant returns nil if s is not a valid constant.
-func parseConstant(s string) *float64 {
+func parseConstant(s string) (float64, error) {
switch s {
case "pi":
- // Assign to variable because can't take address of constant.
- var pi float64 = math.Pi
- return &pi
+ return math.Pi, nil
case "e":
- var e float64 = math.E
- return &e
+ return math.E, nil
}
- return nil
+ return 0, InvalidConstantErr{s}
+}
+
+type InvalidConstantErr struct {
+ s string
+}
+
+func (e InvalidConstantErr) Error() string {
+ return "invalid constant: " + e.s
}