1// Code generated by "go generate gonum.org/v1/gonum/unit”; DO NOT EDIT. 2 3// Copyright ©2014 The Gonum Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7package unit 8 9import ( 10 "errors" 11 "fmt" 12 "math" 13 "unicode/utf8" 14) 15 16// Length represents a length in metres. 17type Length float64 18 19const ( 20 Yottametre Length = 1e24 21 Zettametre Length = 1e21 22 Exametre Length = 1e18 23 Petametre Length = 1e15 24 Terametre Length = 1e12 25 Gigametre Length = 1e9 26 Megametre Length = 1e6 27 Kilometre Length = 1e3 28 Hectometre Length = 1e2 29 Decametre Length = 1e1 30 Metre Length = 1.0 31 Decimetre Length = 1e-1 32 Centimetre Length = 1e-2 33 Millimetre Length = 1e-3 34 Micrometre Length = 1e-6 35 Nanometre Length = 1e-9 36 Picometre Length = 1e-12 37 Femtometre Length = 1e-15 38 Attometre Length = 1e-18 39 Zeptometre Length = 1e-21 40 Yoctometre Length = 1e-24 41) 42 43// Unit converts the Length to a *Unit 44func (l Length) Unit() *Unit { 45 return New(float64(l), Dimensions{ 46 LengthDim: 1, 47 }) 48} 49 50// Length allows Length to implement a Lengther interface 51func (l Length) Length() Length { 52 return l 53} 54 55// From converts the unit into the receiver. From returns an 56// error if there is a mismatch in dimension 57func (l *Length) From(u Uniter) error { 58 if !DimensionsMatch(u, Metre) { 59 *l = Length(math.NaN()) 60 return errors.New("Dimension mismatch") 61 } 62 *l = Length(u.Unit().Value()) 63 return nil 64} 65 66func (l Length) Format(fs fmt.State, c rune) { 67 switch c { 68 case 'v': 69 if fs.Flag('#') { 70 fmt.Fprintf(fs, "%T(%v)", l, float64(l)) 71 return 72 } 73 fallthrough 74 case 'e', 'E', 'f', 'F', 'g', 'G': 75 p, pOk := fs.Precision() 76 w, wOk := fs.Width() 77 const unit = " m" 78 switch { 79 case pOk && wOk: 80 fmt.Fprintf(fs, "%*.*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), p, float64(l)) 81 case pOk: 82 fmt.Fprintf(fs, "%.*"+string(c), p, float64(l)) 83 case wOk: 84 fmt.Fprintf(fs, "%*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), float64(l)) 85 default: 86 fmt.Fprintf(fs, "%"+string(c), float64(l)) 87 } 88 fmt.Fprint(fs, unit) 89 default: 90 fmt.Fprintf(fs, "%%!%c(%T=%g m)", c, l, float64(l)) 91 } 92} 93