github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/unit/conductance.go (about) 1 // Code generated by "go generate github.com/jingcheng-WU/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 // Conductance represents an electrical conductance in Siemens. 17 type Conductance float64 18 19 const Siemens Conductance = 1 20 21 // Unit converts the Conductance to a *Unit. 22 func (co Conductance) Unit() *Unit { 23 return New(float64(co), Dimensions{ 24 CurrentDim: 2, 25 LengthDim: -2, 26 MassDim: -1, 27 TimeDim: 3, 28 }) 29 } 30 31 // Conductance allows Conductance to implement a Conductancer interface. 32 func (co Conductance) Conductance() Conductance { 33 return co 34 } 35 36 // From converts the unit into the receiver. From returns an 37 // error if there is a mismatch in dimension. 38 func (co *Conductance) From(u Uniter) error { 39 if !DimensionsMatch(u, Siemens) { 40 *co = Conductance(math.NaN()) 41 return errors.New("unit: dimension mismatch") 42 } 43 *co = Conductance(u.Unit().Value()) 44 return nil 45 } 46 47 func (co Conductance) Format(fs fmt.State, c rune) { 48 switch c { 49 case 'v': 50 if fs.Flag('#') { 51 fmt.Fprintf(fs, "%T(%v)", co, float64(co)) 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 = " S" 59 switch { 60 case pOk && wOk: 61 fmt.Fprintf(fs, "%*.*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), p, float64(co)) 62 case pOk: 63 fmt.Fprintf(fs, "%.*"+string(c), p, float64(co)) 64 case wOk: 65 fmt.Fprintf(fs, "%*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), float64(co)) 66 default: 67 fmt.Fprintf(fs, "%"+string(c), float64(co)) 68 } 69 fmt.Fprint(fs, unit) 70 default: 71 fmt.Fprintf(fs, "%%!%c(%T=%g S)", c, co, float64(co)) 72 } 73 }