forked from martinlindhe/unit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
length.go
257 lines (211 loc) · 5.9 KB
/
length.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package unit
// Length represents a SI unit of length (in meters, m)
type Length Unit
// ...
const (
// SI
Yoctometer = Meter * 1e-24
Zeptometer = Meter * 1e-21
Attometer = Meter * 1e-18
Femtometer = Meter * 1e-15
Picometer = Meter * 1e-12
Nanometer = Meter * 1e-9
Micrometer = Meter * 1e-6
Millimeter = Meter * 1e-3
Centimeter = Meter * 1e-2
Decimeter = Meter * 1e-1
Meter Length = 1e0
Decameter = Meter * 1e1
Hectometer = Meter * 1e2
Kilometer = Meter * 1e3
ScandinavianMile = Meter * 1e4
Megameter = Meter * 1e6
Gigameter = Meter * 1e9
Terameter = Meter * 1e12
Petameter = Meter * 1e15
Exameter = Meter * 1e18
Zettameter = Meter * 1e21
Yottameter = Meter * 1e24
Ronnameter = Meter * 1e27
Quettameter = Meter * 1e30
// US
Inch = Meter * 0.0254
Hand = Inch * 4
Foot = Inch * 12
Yard = Foot * 3
Link = Chain / 100
Rod = Yard * 5.5
Chain = Rod * 4
Furlong = Chain * 10
Mile = Meter * 1609.344
// US maritime
Fathom = Foot * 6
Cable = NauticalMile / 10
NauticalMile = Meter * 1852
// space
LunarDistance = Kilometer * 384400
AstronomicalUnit = Meter * 149597870700
LightYear = Meter * 9460730472580800
// chemistry
Angstrom = Meter * 1e-10
)
// Yoctometers returns the length in ym
func (l Length) Yoctometers() float64 {
return float64(l / Yoctometer)
}
// Zeptometers returns the length in zm
func (l Length) Zeptometers() float64 {
return float64(l / Zeptometer)
}
// Attometers returns the length in am
func (l Length) Attometers() float64 {
return float64(l / Attometer)
}
// Femtometers returns the length in fm
func (l Length) Femtometers() float64 {
return float64(l / Femtometer)
}
// Picometers returns the length in pm
func (l Length) Picometers() float64 {
return float64(l / Picometer)
}
// Nanometers returns the length in nm
func (l Length) Nanometers() float64 {
return float64(l / Nanometer)
}
// Micrometers returns the length in microms
func (l Length) Micrometers() float64 {
return float64(l / Micrometer)
}
// Millimeters returns the length in mm
func (l Length) Millimeters() float64 {
return float64(l / Millimeter)
}
// Centimeters returns the length in cm
func (l Length) Centimeters() float64 {
return float64(l / Centimeter)
}
// Decimeters returns the length in dm
func (l Length) Decimeters() float64 {
return float64(l / Decimeter)
}
// Meters returns the length in m
func (l Length) Meters() float64 {
return float64(l)
}
// Decameters returns the length in dam
func (l Length) Decameters() float64 {
return float64(l / Decameter)
}
// Hectometers returns the length in hm
func (l Length) Hectometers() float64 {
return float64(l / Hectometer)
}
// Kilometers returns the length in km
func (l Length) Kilometers() float64 {
return float64(l / Kilometer)
}
// ScandinavianMiles returns the length in in scandinavian miles (1 scandmile = 10 km)
func (l Length) ScandinavianMiles() float64 {
return float64(l / ScandinavianMile)
}
// Megameters returns the length in in Mm
func (l Length) Megameters() float64 {
return float64(l / Megameter)
}
// Gigameters returns the length in in Gm
func (l Length) Gigameters() float64 {
return float64(l / Gigameter)
}
// Terameters returns the length in in Tm
func (l Length) Terameters() float64 {
return float64(l / Terameter)
}
// Petameters returns the length in in Pm
func (l Length) Petameters() float64 {
return float64(l / Petameter)
}
// Exameters returns the length in in Em
func (l Length) Exameters() float64 {
return float64(l / Exameter)
}
// Zettameters returns the length in in Zm
func (l Length) Zettameters() float64 {
return float64(l / Zettameter)
}
// Yottameters returns the length in in Ym
func (l Length) Yottameters() float64 {
return float64(l / Yottameter)
}
// Ronnameters returns the length in in Rm
func (l Length) Ronnameters() float64 {
return float64(l / Ronnameter)
}
// Quettameters returns the length in in Qm
func (l Length) Quettameters() float64 {
return float64(l / Quettameter)
}
// Inches returns the length in in
func (l Length) Inches() float64 {
return float64(l / Inch)
}
// Hands returns the length in h
func (l Length) Hands() float64 {
return float64(l / Hand)
}
// Feet returns the length in ft
func (l Length) Feet() float64 {
return float64(l / Foot)
}
// Yards returns the length in yd
func (l Length) Yards() float64 {
return float64(l / Yard)
}
// Rods returns the length in rod
func (l Length) Rods() float64 {
return float64(l / Rod)
}
// Chains returns the length in ch
func (l Length) Chains() float64 {
return float64(l / Chain)
}
// Links return the length in li
func (l Length) Links() float64 {
return float64(l / Link)
}
// Furlongs returns the length in furlong
func (l Length) Furlongs() float64 {
return float64(l / Furlong)
}
// Miles returns the length in mi
func (l Length) Miles() float64 {
return float64(l / Mile)
}
// Fathoms returns the length in fathom
func (l Length) Fathoms() float64 {
return float64(l / Fathom)
}
// Cables returns the length in cable
func (l Length) Cables() float64 {
return float64(l / Cable)
}
// NauticalMiles returns the length in nm
func (l Length) NauticalMiles() float64 {
return float64(l / NauticalMile)
}
// LunarDistances returns the length in ld
func (l Length) LunarDistances() float64 {
return float64(l / LunarDistance)
}
// AstronomicalUnits returns the length in au
func (l Length) AstronomicalUnits() float64 {
return float64(l / AstronomicalUnit)
}
// LightYears returns the length in ly
func (l Length) LightYears() float64 {
return float64(l / LightYear)
}
// Angstroms returns the length in A
func (l Length) Angstroms() float64 {
return float64(l / Angstrom)
}