gonum.org/v1/gonum@v0.14.0/unit/acceleration.go (about) 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 7 package unit 8 9 import ( 10 "errors" 11 "fmt" 12 "math" 13 "unicode/utf8" 14 ) 15 16 // Acceleration represents an acceleration in metres per second squared. 17 type Acceleration float64 18 19 // Unit converts the Acceleration to a *Unit. 20 func (a Acceleration) Unit() *Unit { 21 return New(float64(a), Dimensions{ 22 LengthDim: 1, 23 TimeDim: -2, 24 }) 25 } 26 27 // Acceleration allows Acceleration to implement a Accelerationer interface. 28 func (a Acceleration) Acceleration() Acceleration { 29 return a 30 } 31 32 // From converts the unit into the receiver. From returns an 33 // error if there is a mismatch in dimension. 34 func (a *Acceleration) From(u Uniter) error { 35 if !DimensionsMatch(u, Acceleration(0)) { 36 *a = Acceleration(math.NaN()) 37 return errors.New("unit: dimension mismatch") 38 } 39 *a = Acceleration(u.Unit().Value()) 40 return nil 41 } 42 43 func (a Acceleration) Format(fs fmt.State, c rune) { 44 switch c { 45 case 'v': 46 if fs.Flag('#') { 47 fmt.Fprintf(fs, "%T(%v)", a, float64(a)) 48 return 49 } 50 fallthrough 51 case 'e', 'E', 'f', 'F', 'g', 'G': 52 p, pOk := fs.Precision() 53 w, wOk := fs.Width() 54 const unit = " m s^-2" 55 switch { 56 case pOk && wOk: 57 fmt.Fprintf(fs, "%*.*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), p, float64(a)) 58 case pOk: 59 fmt.Fprintf(fs, "%.*"+string(c), p, float64(a)) 60 case wOk: 61 fmt.Fprintf(fs, "%*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), float64(a)) 62 default: 63 fmt.Fprintf(fs, "%"+string(c), float64(a)) 64 } 65 fmt.Fprint(fs, unit) 66 default: 67 fmt.Fprintf(fs, "%%!%c(%T=%g m s^-2)", c, a, float64(a)) 68 } 69 }