units

package module
v0.0.0-...-cd506ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 0 Imported by: 0

README

units

convenience functions for units of measure and their conversions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Magnitude

type Magnitude struct {
	Unit     Unit
	Quantity float64
}

a Magnitude unambiguously indicates a magnitude of something by combining a scalar and a unit example: 3.5 teaspons

func (Magnitude) Convert

func (from Magnitude) Convert(to Unit) (float64, error)

type Unit

type Unit struct {
	Symbol string
	Name   string
	Kind   UnitKind
	Ratio  float64
}

a Unit is a unit of measure

func (Unit) Convert

func (from Unit) Convert(to Unit) (float64, error)

to Convert between two units is to return their Ratio

type UnitKind

type UnitKind uint8

a UnitKind indicates what kind of unit we're dealing with and can be used to enforce legal conversions. for example, it's not legal to convert between mile and teaspoon

const (
	Volume UnitKind = iota
	Weight
	Length
)

type UnitMismatchError

type UnitMismatchError struct {
	Unit1 Unit
	Unit2 Unit
	Msg   string
}

UnitMismatchError is an [Error] that contains information about the mismatched units

func (UnitMismatchError) Error

func (e UnitMismatchError) Error() string

Directories

Path Synopsis
cmd
cli command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL