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