github.com/gopherd/gonum@v0.0.4/unit/constant/boltzmann.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 // Boltzmann is the Boltzmann constant (k), it relates the average relative kinetic energy of particles in a gas with the temperature of the gas. 16 // The dimensions of Boltzmann are kg m^2 K^-1 s^-2. The constant is exact. 17 const Boltzmann = boltzmannUnits(1.380649e-23) 18 19 type boltzmannUnits float64 20 21 // Unit converts the boltzmannUnits to a *unit.Unit 22 func (cnst boltzmannUnits) Unit() *unit.Unit { 23 return unit.New(float64(cnst), unit.Dimensions{ 24 unit.MassDim: 1, 25 unit.LengthDim: 2, 26 unit.TimeDim: -2, 27 unit.TemperatureDim: -1, 28 }) 29 } 30 31 func (cnst boltzmannUnits) Format(fs fmt.State, c rune) { 32 switch c { 33 case 'v': 34 if fs.Flag('#') { 35 fmt.Fprintf(fs, "%T(%v)", cnst, float64(cnst)) 36 return 37 } 38 fallthrough 39 case 'e', 'E', 'f', 'F', 'g', 'G': 40 p, pOk := fs.Precision() 41 w, wOk := fs.Width() 42 switch { 43 case pOk && wOk: 44 fmt.Fprintf(fs, "%*.*"+string(c), w, p, cnst.Unit()) 45 case pOk: 46 fmt.Fprintf(fs, "%.*"+string(c), p, cnst.Unit()) 47 case wOk: 48 fmt.Fprintf(fs, "%*"+string(c), w, cnst.Unit()) 49 default: 50 fmt.Fprintf(fs, "%"+string(c), cnst.Unit()) 51 } 52 default: 53 fmt.Fprintf(fs, "%%!"+string(c)+"(constant.boltzmannUnits=%v kg m^2 K^-1 s^-2)", float64(cnst)) 54 } 55 }