aboutsummaryrefslogtreecommitdiffstats
path: root/const.go
blob: 0aa5a37ae8cd55c10d2ec1a17d6178ada85622bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main

import "math"

const (
	// Vacuum permettivity [C²/(N·m²)]
	e0 = 8.8541878188e-12
)

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

type InvalidConstantErr struct {
	s string
}

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