github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/unit/constant/gravitational.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  // Gravitational is the universal gravitational constant (G), the proportionality constant connecting the gravitational force between two bodies.
    16  // The dimensions of Gravitational are m^3 kg^-1 s^-2. The standard uncertainty of the constant is 1.5e-15 m^3 kg^-1 s^-2.
    17  const Gravitational = gravitationalUnits(6.6743e-11)
    18  
    19  type gravitationalUnits float64
    20  
    21  // Unit converts the gravitationalUnits to a *unit.Unit
    22  func (cnst gravitationalUnits) Unit() *unit.Unit {
    23  	return unit.New(float64(cnst), unit.Dimensions{
    24  		unit.MassDim:   -1,
    25  		unit.LengthDim: 3,
    26  		unit.TimeDim:   -2,
    27  	})
    28  }
    29  
    30  func (cnst gravitationalUnits) 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.gravitationalUnits=%v m^3 kg^-1 s^-2)", float64(cnst))
    53  	}
    54  }