github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/unit/constant/faraday.go (about)

     1  // Code generated by "go generate github.com/jingcheng-WU/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/jingcheng-WU/gonum/unit"
    13  )
    14  
    15  // Faraday is the Faraday constant, the magnitude of electric charge per mole of electrons.
    16  // The dimensions of Faraday are A s mol^-1. The constant is exact.
    17  const Faraday = faradayUnits(96485.33212)
    18  
    19  type faradayUnits float64
    20  
    21  // Unit converts the faradayUnits to a *unit.Unit
    22  func (cnst faradayUnits) Unit() *unit.Unit {
    23  	return unit.New(float64(cnst), unit.Dimensions{
    24  		unit.CurrentDim: 1,
    25  		unit.TimeDim:    1,
    26  		unit.MoleDim:    -1,
    27  	})
    28  }
    29  
    30  func (cnst faradayUnits) 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.faradayUnits=%v A s mol^-1)", float64(cnst))
    53  	}
    54  }