{"id":25861699,"url":"https://github.com/quartercastle/si","last_synced_at":"2026-06-09T03:01:40.367Z","repository":{"id":57710304,"uuid":"511242808","full_name":"quartercastle/si","owner":"quartercastle","description":"SI unit annotation and conversion library for Go","archived":false,"fork":false,"pushed_at":"2022-11-24T21:23:00.000Z","size":15,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T11:59:29.423Z","etag":null,"topics":["golang","math","si","unit"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quartercastle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-06T18:02:47.000Z","updated_at":"2022-07-08T20:54:21.000Z","dependencies_parsed_at":"2022-09-26T21:21:57.639Z","dependency_job_id":null,"html_url":"https://github.com/quartercastle/si","commit_stats":null,"previous_names":["kvartborg/si"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartercastle%2Fsi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartercastle%2Fsi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartercastle%2Fsi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartercastle%2Fsi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quartercastle","download_url":"https://codeload.github.com/quartercastle/si/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241439487,"owners_count":19963097,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","math","si","unit"],"created_at":"2025-03-01T23:45:05.421Z","updated_at":"2026-06-09T03:01:40.303Z","avatar_url":"https://github.com/quartercastle.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# si\n\n[![GoDoc](https://godoc.org/github.com/quartercastle/si?status.svg)](https://pkg.go.dev/github.com/quartercastle/si?tab=doc)\n[![Go Report Card](https://goreportcard.com/badge/github.com/quartercastle/si)](https://goreportcard.com/report/github.com/quartercastle/si)\n\n\u003e NOTE: this is still a work in progress\n\nsi is a unit annotation and conversion library. Its different from other strongly\ntyped si/unit libraries in the way that all types are aliases to `float64`\ninstead of concrete types.\nThe benefit of this approach is that casting can be avoided which results in\nmore readable code that somewhat resembles the math equation.\n\nTo prove my point i have created an example using Einstein's mass-energy equivalence formular $E=mc^2$.\n\n```go\n// possible using aliased si types\n24.965421631578266*MWh == 1*mg * math.Pow(c, 2)\n\n// problem with conrete si types...\n24.965421631578266*MWh == MWh(float64(1*mg) * math.Pow(c, 2))\n```\n\nAs it can be seen in the example above casting ends up hurting readability and\nit really doesn't add anything in terms of type safety because casting will be so\nprevalent. It will only be as safe as the aliased approach used in this library.\n\nAnother benefit is that derived si types can easily be defined on the fly, this\nis not possible when using concrete types unless casting is involved.\n\n```go\nconst SpeedOfLight = 299792458 * (Meter/Second)\n```\n\nIt will also work well with the `math` package from standard lib or any other\nthirdparty library which is using `float64` as input or output types.\nBelow is an example of how it could be used with a\n[vector](https://github.com/quartercastle/vector) package.\n\n```go\nVector{10 * (Meter/Second)}.Rotate(45*Degree)\n```\n\n### Install\n\n```sh\ngo get github.com/quartercastle/si\n```\n\n### Usage\n\n```go\nfunc MassEnergyEquivalence(energy si.Energy, mass si.Mass) bool {\n  return energy == mass * math.Pow(si.SpeedOfLight, 2)\n}\n\n\nMassEnergyEquivalence(24.965421631578266*si.MegawattHour, 1*si.Milligram)\n```\n\n\n## Credits\nThis project is heavily inspired by [github.com/martinlindhe/unit](https://github.com/martinlindhe/unit),\nwhich is a strongly typed unit conversion library that i have used a lot\npreviously. It would not exist without the knowledge i have gained by using this\nlibrary.\n\n## License\nThis project is licensed under the [MIT License](https://github.com/quartercastle/si/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquartercastle%2Fsi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquartercastle%2Fsi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquartercastle%2Fsi/lists"}