https://github.com/dnesting/unit
https://github.com/dnesting/unit
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dnesting/unit
- Owner: dnesting
- Created: 2019-11-29T17:34:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-01T23:28:32.000Z (over 5 years ago)
- Last Synced: 2024-06-20T05:02:08.369Z (over 1 year ago)
- Language: Go
- Size: 39.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# unit
[](https://godoc.org/github.com/dnesting/unit)
[](https://travis-ci.org/dnesting/unit)
[](https://coveralls.io/github/dnesting/unit?branch=master)
[](https://goreportcard.com/report/github.com/dnesting/unit)
This is a work in progress.
The goal is to enable light-weight operations on values with units attached to them, including implicit unit conversion.
For instance, the following should be possible:
```go
mps := si.Meter.Div(si.Second)
speed := mps(5) // 5 m/s
dist := speed.Mul(si.FromDuration(5*time.Second))
fmt.Println(dist) // "25 m"
mph := us.Mile.Div(us.Hour)
speed = speed.Convert(mph) // now "11.185 mi/hr"
fmt.Println(dist.Div(speed)) // "5 s"
```
Stretch goal is compatibility with GNU Units `definitions.units`, something like:
```go
defs := unitdef.Definitions() // read and parse definitions.units
mps = defs.Must("m/s")
dist := mps(5).Mul(si.Second(5))
fmt.Println(dist) // "25 m"
```