aboutsummaryrefslogtreecommitdiffstats
path: root/const.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-10-01 20:02:22 -0400
committerSam Anthony <sam@samanthony.xyz>2023-10-01 20:02:22 -0400
commit4f9e220638ea62443db25d252c4e12ede2c7f9c5 (patch)
treeed40edf989f2907e58e3d5fd0fd0a85cde919386 /const.go
parent6e3073f5e835b19b39d0853dece386067218b1ce (diff)
downloadpfc-4f9e220638ea62443db25d252c4e12ede2c7f9c5.zip
error handling and tidying
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
}