github.com/gopherd/gonum@v0.0.4/unit/constant/avogadro.go (about) 1 // Code generated by "go generate github.com/gopherd/gonum/unit/constant”; DO NOT EDIT. 2 3 // Copyright ©2019 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 constant 8 9 import ( 10 "fmt" 11 12 "github.com/gopherd/gonum/unit" 13 ) 14 15 // Avogadro is the Avogadro constant (A), the number of constituent particles contained in one mole of a substance. 16 // The dimension of Avogadro is mol^-1. The constant is exact. 17 const Avogadro = avogadroUnits(6.02214076e+23) 18 19 type avogadroUnits float64 20 21 // Unit converts the avogadroUnits to a *unit.Unit 22 func (cnst avogadroUnits) Unit() *unit.Unit { 23 return unit.New(float64(cnst), unit.Dimensions{ 24 unit.MoleDim: -1, 25 }) 26 } 27 28 func (cnst avogadroUnits) Format(fs fmt.State, c rune) { 29 switch c { 30 case 'v': 31 if fs.Flag('#') { 32 fmt.Fprintf(fs, "%T(%v)", cnst, float64(cnst)) 33 return 34 } 35 fallthrough 36 case 'e', 'E', 'f', 'F', 'g', 'G': 37 p, pOk := fs.Precision() 38 w, wOk := fs.Width() 39 switch { 40 case pOk && wOk: 41 fmt.Fprintf(fs, "%*.*"+string(c), w, p, cnst.Unit()) 42 case pOk: 43 fmt.Fprintf(fs, "%.*"+string(c), p, cnst.Unit()) 44 case wOk: 45 fmt.Fprintf(fs, "%*"+string(c), w, cnst.Unit()) 46 default: 47 fmt.Fprintf(fs, "%"+string(c), cnst.Unit()) 48 } 49 default: 50 fmt.Fprintf(fs, "%%!"+string(c)+"(constant.avogadroUnits=%v mol^-1)", float64(cnst)) 51 } 52 }