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