gonum.org/v1/gonum@v0.14.0/unit/absorbedradioactivedose.go (about)

     1  // Code generated by "go generate gonum.org/v1/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  // AbsorbedRadioactiveDose is a measure of absorbed dose of ionizing radiation in grays.
    17  type AbsorbedRadioactiveDose float64
    18  
    19  const Gray AbsorbedRadioactiveDose = 1
    20  
    21  // Unit converts the AbsorbedRadioactiveDose to a *Unit.
    22  func (a AbsorbedRadioactiveDose) Unit() *Unit {
    23  	return New(float64(a), Dimensions{
    24  		LengthDim: 2,
    25  		TimeDim:   -2,
    26  	})
    27  }
    28  
    29  // AbsorbedRadioactiveDose allows AbsorbedRadioactiveDose to implement a AbsorbedRadioactiveDoseer interface.
    30  func (a AbsorbedRadioactiveDose) AbsorbedRadioactiveDose() AbsorbedRadioactiveDose {
    31  	return a
    32  }
    33  
    34  // From converts the unit into the receiver. From returns an
    35  // error if there is a mismatch in dimension.
    36  func (a *AbsorbedRadioactiveDose) From(u Uniter) error {
    37  	if !DimensionsMatch(u, Gray) {
    38  		*a = AbsorbedRadioactiveDose(math.NaN())
    39  		return errors.New("unit: dimension mismatch")
    40  	}
    41  	*a = AbsorbedRadioactiveDose(u.Unit().Value())
    42  	return nil
    43  }
    44  
    45  func (a AbsorbedRadioactiveDose) Format(fs fmt.State, c rune) {
    46  	switch c {
    47  	case 'v':
    48  		if fs.Flag('#') {
    49  			fmt.Fprintf(fs, "%T(%v)", a, float64(a))
    50  			return
    51  		}
    52  		fallthrough
    53  	case 'e', 'E', 'f', 'F', 'g', 'G':
    54  		p, pOk := fs.Precision()
    55  		w, wOk := fs.Width()
    56  		const unit = " Gy"
    57  		switch {
    58  		case pOk && wOk:
    59  			fmt.Fprintf(fs, "%*.*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), p, float64(a))
    60  		case pOk:
    61  			fmt.Fprintf(fs, "%.*"+string(c), p, float64(a))
    62  		case wOk:
    63  			fmt.Fprintf(fs, "%*"+string(c), pos(w-utf8.RuneCount([]byte(unit))), float64(a))
    64  		default:
    65  			fmt.Fprintf(fs, "%"+string(c), float64(a))
    66  		}
    67  		fmt.Fprint(fs, unit)
    68  	default:
    69  		fmt.Fprintf(fs, "%%!%c(%T=%g Gy)", c, a, float64(a))
    70  	}
    71  }