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

     1  // Code generated by "go generate github.com/jingcheng-WU/gonum/unit”; DO NOT EDIT.
     2  
     3  // Copyright ©2014 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 unit
     8  
     9  import (
    10  	"errors"
    11  	"fmt"
    12  	"math"
    13  	"unicode/utf8"
    14  )
    15  
    16  // Inductance represents an electrical inductance in Henry.
    17  type Inductance float64
    18  
    19  const Henry Inductance = 1
    20  
    21  // Unit converts the Inductance to a *Unit.
    22  func (i Inductance) Unit() *Unit {
    23  	return New(float64(i), Dimensions{
    24  		CurrentDim: -2,
    25  		LengthDim:  2,
    26  		MassDim:    1,
    27  		TimeDim:    -2,
    28  	})
    29  }
    30  
    31  // Inductance allows Inductance to implement a Inductancer interface.
    32  func (i Inductance) Inductance() Inductance {
    33  	return i
    34  }
    35  
    36  // From converts the unit into the receiver. From returns an
    37  // error if there is a mismatch in dimension.
    38  func (i *Inductance) From(u Uniter) error {
    39  	if !DimensionsMatch(u, Henry) {
    40  		*i = Inductance(math.NaN())
    41  		return errors.New("unit: dimension mismatch")
    42  	}
    43  	*i = Inductance(u.Unit().Value())
    44  	return nil
    45  }
    46  
    47  func (i Inductance) Format(fs fmt.State, c rune) {
    48  	switch c {
    49  	case 'v':
    50  		if fs.Flag('#') {
    51  			fmt.Fprintf(fs, "%T(%v)", i, float64(i))
    52  			return
    53  		}
    54  		fallthrough
    55  	case 'e', 'E', 'f', 'F', 'g', 'G':
    56  		p, pOk := fs.Precision()
    57  		w, wOk := fs.Width()
    58  		const unit = " H"
    59  		switch {
    60  		case pOk && wOk:
    61  			fmt.Fprintf(fs, "%*.*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), p, float64(i))
    62  		case pOk:
    63  			fmt.Fprintf(fs, "%.*"+string(c), p, float64(i))
    64  		case wOk:
    65  			fmt.Fprintf(fs, "%*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), float64(i))
    66  		default:
    67  			fmt.Fprintf(fs, "%"+string(c), float64(i))
    68  		}
    69  		fmt.Fprint(fs, unit)
    70  	default:
    71  		fmt.Fprintf(fs, "%%!%c(%T=%g H)", c, i, float64(i))
    72  	}
    73  }