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