{"id":22924201,"url":"https://github.com/benbarsdell/rtunits","last_synced_at":"2025-04-01T14:47:00.382Z","repository":{"id":73394088,"uuid":"205954287","full_name":"benbarsdell/rtunits","owner":"benbarsdell","description":"A single-header C++11 library for working with physical quantities at runtime.","archived":false,"fork":false,"pushed_at":"2023-06-18T13:38:47.000Z","size":68,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-07T09:32:01.887Z","etag":null,"topics":["astronomy-instrumentation","conversion-library","cpp-library","dimensional-analysis","single-header-lib","units-measures-converter","units-of-measure","units-of-measurement"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benbarsdell.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,"governance":null}},"created_at":"2019-09-03T00:04:09.000Z","updated_at":"2023-01-07T12:12:54.000Z","dependencies_parsed_at":"2023-10-20T18:21:35.238Z","dependency_job_id":null,"html_url":"https://github.com/benbarsdell/rtunits","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbarsdell%2Frtunits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbarsdell%2Frtunits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbarsdell%2Frtunits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbarsdell%2Frtunits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benbarsdell","download_url":"https://codeload.github.com/benbarsdell/rtunits/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246659774,"owners_count":20813331,"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":["astronomy-instrumentation","conversion-library","cpp-library","dimensional-analysis","single-header-lib","units-measures-converter","units-of-measure","units-of-measurement"],"created_at":"2024-12-14T08:19:52.808Z","updated_at":"2025-04-01T14:47:00.346Z","avatar_url":"https://github.com/benbarsdell.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RT-Units\n\n[![Build Status](https://github.com/benbarsdell/rtunits/actions/workflows/ci.yml/badge.svg?event=push)](https://github.com/benbarsdell/rtunits/actions?query=workflow%3ACI)\n\n\nRT-Units - A single-header C++11 library for working with physical\nquantities at runtime, including support for parsing and\nserialization.\n\nThe `rtunits::Quantity` template represents a physical quantity with a\nmagnitude and dimensions. It supports an extensive set of physical\nunits and scale prefixes, and implements robust parsing and\nserialization.\n\n# Example\n\n```C++\n#include \u003ciostream\u003e\n#include \u003crtunits.hpp\u003e\n\nusing rtunits::Quantity64;\nusing rtunits::SpecificQuantity64;\nusing Dims = rtunits::Dimensions;\n\nint main(int argc, char* argv[]) {\n  Quantity64 force(1.25, \"kN\");\n  Quantity64 displacement(12.0, \"mm\");\n  Quantity64 work = force * displacement + 5. * Quantity64::joule();\n  std::cout \u003c\u003c \"Work: \" \u003c\u003c work \u003c\u003c '\\n';\n  std::cout \u003c\u003c \"Dims: \" \u003c\u003c work.dimensions() \u003c\u003c '\\n';\n  std::cout \u003c\u003c (work.dimensions() == Dims::Force() * Dims::Length()) \u003c\u003c '\\n';\n  std::cout \u003c\u003c (work == Quantity64(20, \"J\")) \u003c\u003c '\\n';\n  std::cout \u003c\u003c (work.value(\"mW s\") == 20e3) \u003c\u003c '\\n';\n\n  SpecificQuantity64 dm(500., \"pc/cm^3\");\n  dm *= 2;\n  std::cout \u003c\u003c \"DM: \" \u003c\u003c dm \u003c\u003c '\\n';\n  std::cout \u003c\u003c \"  = \" \u003c\u003c static_cast\u003cQuantity64\u003e(dm) \u003c\u003c std::endl;\n}\n```\n\nOutput:\n\n```\nWork: 20 m^2 kg s^-2\nDims: L^2 M T^-2\n1\n1\n1\nDM: 1000 pc/cm^3\n  = 3.08568e+25 m^-2\n```\n\n# Performance\n\nUnits are parsed using a very large regular expression, which can be slow.\nTo improve performance, consider doing the following:\n\n- Define RTUNITS_USE_BOOST_REGEX=1 to use [boost::regex](https://github.com/boostorg/regex),\n  which is 4-8x faster than std::regex. (Note that boost::regex can be used as a\n  standalone header-only library without requiring the rest of Boost).\n- Define RTUNITS_NO_ASTRONOMY_UNITS=1, RTUNITS_NO_CGS_UNITS=1, and/or\n  RTUNITS_NO_MISC_UNITS=1 before including `rtunits.hpp` to disable support for\n  unneeded units. This can speed up parsing by up to 2x.\n\n\n# Error handling\n\nExceptions are used by default, but can be disabled by defining\n`RTUNITS_USE_EXCEPTIONS` to 0 before including the rtunits header:\n\n```\n#define RTUNITS_USE_EXCEPTIONS 0\n#include \u003crtunits.hpp\u003e\n```\n\n# Tests\n\nRun tests using the following commands:\n\n    $ mkdir build\n    $ cd build\n    $ cmake ..\n    $ make check\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbarsdell%2Frtunits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenbarsdell%2Frtunits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbarsdell%2Frtunits/lists"}