mp-units

The quantities and units library for C++

https://github.com/mpusz/mp-units

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 39 committers (2.6%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.5%) to scientific vocabulary

Keywords

cmake conan cpp cpp20 cpp23 dimensional-analysis dimensions isq library physical-quantities physical-units quantity quantity-manipulation safety si system-of-quantities system-of-units units units-of-measure units-of-measurement
Last synced: 4 months ago · JSON representation ·

Repository

The quantities and units library for C++

Basic Info
Statistics
  • Stars: 1,232
  • Watchers: 36
  • Forks: 104
  • Open Issues: 69
  • Releases: 16
Topics
cmake conan cpp cpp20 cpp23 dimensional-analysis dimensions isq library physical-quantities physical-units quantity quantity-manipulation safety si system-of-quantities system-of-units units units-of-measure units-of-measurement
Created over 7 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation

README.md

GitHub license GitHub license

Conan CI CMake CI clang-tidy CI Freestanding CI Formatting CI GitHub Workflow Documentation

Conan stable Conan testing

mp-units - The quantities and units library for C++

The mp-units library might be the subject of ISO standardization for C++29. More on this can be found in the following ISO C++ proposals:

We are actively looking for parties interested in field-trialing the library.

Documentation

An extensive project documentation can be found on mp-units GitHub Pages. It includes installation instructions and a detailed user's guide.

TL;DR

mp-units is a compile-time enabled Modern C++ library that provides compile-time dimensional analysis and unit/quantity manipulation.

Here is a small example of possible operations:

```cpp

include

using namespace mpunits; using namespace mpunits::si::unit_symbols;

// simple numeric operations static_assert(10 * km / 2 == 5 * km);

// conversions to common units staticassert(1 * h == 3600 * s); staticassert(1 * km + 1 * m == 1001 * m);

// derived quantities staticassert(1 * km / (1 * s) == 1000 * m / s); staticassert(2 * km / h * (2 * h) == 4 * km); static_assert(2 * km / (2 * km / h) == 1 * h);

static_assert(2 * m * (3 * m) == 6 * m2);

static_assert(10 * km / (5 * km) == 2 * one);

static_assert(1000 / (1 * s) == 1 * kHz); ```

Try it on the Compiler Explorer.

This library heavily uses C++20 features (concepts, classes as NTTPs, ...). Thanks to them the user gets a powerful but still easy to use interfaces and all unit conversions and dimensional analysis can be performed without sacrificing on runtime performance or accuracy. Please see the below example for a quick preview of basic library features:

```cpp

include

include

include

include

include

include

include

using namespace mp_units;

constexpr QuantityOfisq::speed auto avg_speed(QuantityOfisq::length auto d, QuantityOfisq::time auto t) { return d / t; }

int main() { using namespace mpunits::si::unitsymbols; using namespace mpunits::international::unitsymbols;

constexpr quantity v1 = 110 * km / h; constexpr quantity v2 = 70 * mph; constexpr quantity v3 = avgspeed(220. * isq::distance[km], 2 * h); constexpr quantity v4 = avgspeed(isq::distance(140. * mi), 2 * h); constexpr quantity v5 = v3.in(m / s); constexpr quantity v6 = valuecast(v4); constexpr quantity v7 = valuecast(v6);

std::cout << v1 << '\n'; // 110 km/h std::cout << std::setw(10) << std::setfill('') << v2 << '\n'; // *70 mi/h std::cout << std::format("{:^10}\n", v3); // 110 km/h std::println("{:%N in %U of %D}", v4); // 70 in mi/h of LT⁻¹ std::println("{::N[.2f]}", v5); // 30.56 m/s std::println("{::N[.2f]U[dn]}", v6); // 31.29 m⋅s⁻¹ std::println("{:%N}", v7); // 31 } ```

Try it on the Compiler Explorer.

Try It Out

The Compiler Explorer

As can be see in the previous chapter, the mp-units library is available in the Compiler Explorer. Use it to get a fast hands-on experience or try some ideas.

GitHub Codespaces

For more advanced development or contributions we encourage you to use our pre-configured GitHub Codespaces environment. You can either click the button below

Open in GitHub Codespaces

or navigate to the main page of the repository and click "Code" button -> "Codespaces" tab -> "Create codespace on master".

You can also use the pre-configured devcontainer and Docker image manually within your IDE.

For detailed environment documentation, see .devcontainer/README.md.

Owner

  • Name: Mateusz Pusz
  • Login: mpusz
  • Kind: user
  • Location: Gdańsk, Poland
  • Company: @train-it-eu

Software architect, chief engineer, security champion, and C++ trainer with more than 14 years of experience in designing, writing and maintaining C++ code.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it using these metadata."

title: mp-units
abstract: >-
  A compile-time enabled Modern C++ library that provides compile-time
  dimensional analysis and unit/quantity manipulation.
keywords:
  - c++
  - library
  - dimensional-analysis
  - system-of-units
  - units
  - quantities
  - physical-quantities
  - physical-units
  - units-of-measurement
  - quantity-manipulation
type: software
license: MIT

# The below lists individual authors that contributed at least 50 commits to the source code repository.
# The rest of project's contributors are collectively referred to as "The mp-units project team".
authors:
  - given-names: Mateusz
    family-names: Pusz
    orcid: https://orcid.org/0000-0003-0680-0765
  - given-names: "Johel Ernesto"
    family-names: "Guerrero Peña"
  - given-names: "Chip"
    family-names: "Hogg"
  - name: "The mp-units project team"

contact:
  - email: mateusz.pusz@gmail.com
    given-names: Mateusz
    family-names: Pusz

repository-code: "https://github.com/mpusz/mp-units"
url: "https://mpusz.github.io/mp-units"
repository-artifact: "https://conan.io/center/mp-units"

version: 2.4.0
date-released: "2024-11-05"
identifiers:
  - description: "The GitHub release URL of tag 2.4.0"
    type: url
    value: "https://github.com/mpusz/mp-units/releases/tag/v2.4.0"

GitHub Events

Total
  • Create event: 5
  • Commit comment event: 105
  • Release event: 1
  • Issues event: 85
  • Watch event: 144
  • Delete event: 5
  • Issue comment event: 335
  • Push event: 254
  • Pull request review comment event: 340
  • Pull request review event: 336
  • Pull request event: 46
  • Fork event: 19
Last Year
  • Create event: 5
  • Commit comment event: 105
  • Release event: 1
  • Issues event: 85
  • Watch event: 144
  • Delete event: 5
  • Issue comment event: 335
  • Push event: 254
  • Pull request review comment event: 340
  • Pull request review event: 336
  • Pull request event: 46
  • Fork event: 19

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 3,945
  • Total Committers: 39
  • Avg Commits per committer: 101.154
  • Development Distribution Score (DDS): 0.148
Past Year
  • Commits: 644
  • Committers: 11
  • Avg Commits per committer: 58.545
  • Development Distribution Score (DDS): 0.157
Top Committers
Name Email Commits
Mateusz Pusz m****z@g****m 3,363
Chip Hogg c****g@a****h 148
Johel Ernesto Guerrero Peña j****p@g****m 127
Jonas Hoppe 1****e 44
rbrugo b****o@g****m 44
Yves Delley d****s@g****h 41
Ramzi Sabra y****a@h****m 20
Markus Hofbauer m****r@t****e 19
Andy Little k****s@y****m 16
Roth Michaels r****h@r****s 15
Antony Peacock a****k@g****m 14
Mike Ford m****y@h****m 13
Oliver Schönrock o****r@o****t 13
Ralph J. Steinhagen r****n@g****e 10
Frank Dischner f****r@g****m 9
Nick Thompson n****7@p****m 6
Nebojsa Cvetkovic n****t@g****m 5
Björn Schäpers s****s@k****m 5
Jan Sende 4****e 4
Soham Roy s****9@g****m 3
Uilian Ries u****s@g****m 3
jvocht j****p@m****g 3
Christoph Seitz c****z@p****e 2
dkavolis 1****s 2
nbresler n****r@a****m 2
dbraeckelmann 1****n 1
Cazadorro n****e 1
Evelyn LePain e****n@s****m 1
Tobias Lorenz t****z@g****t 1
TheCoconutChef t****f@g****m 1
and 9 more...

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 164
  • Total pull requests: 91
  • Average time to close issues: 10 months
  • Average time to close pull requests: about 2 months
  • Total issue authors: 50
  • Total pull request authors: 20
  • Average comments per issue: 5.72
  • Average comments per pull request: 2.34
  • Merged pull requests: 67
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 63
  • Pull requests: 40
  • Average time to close issues: 6 days
  • Average time to close pull requests: 4 days
  • Issue authors: 25
  • Pull request authors: 12
  • Average comments per issue: 3.14
  • Average comments per pull request: 1.63
  • Merged pull requests: 29
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mpusz (62)
  • JohelEGP (20)
  • chiphogg (9)
  • Becheler (4)
  • kwikius (4)
  • n0F4x (4)
  • Cazadorro (3)
  • WBurzynski (3)
  • AnthonyVH (3)
  • VictorEijkhout (3)
  • burnpanck (3)
  • khansson (2)
  • psychon (2)
  • CrustyAuklet (2)
  • KangarooKoala (2)
Pull Request Authors
  • burnpanck (25)
  • mpusz (19)
  • rothmichaels (16)
  • chiphogg (12)
  • JohelEGP (6)
  • nebkat (6)
  • bourumir-wyngs (2)
  • alejandro-alvarez-sonarsource (2)
  • jharwell (2)
  • hasenradball (2)
  • NAThompson (2)
  • EALePain (2)
  • FrancoisCarouge (2)
  • czjhoppe (2)
  • jvocht (1)
Top Labels
Issue Labels
design (35) enhancement (31) question (20) iso (14) good first issue (12) help wanted (10) refactor (8) bug (7) high priority (6) gated (5) documentation (3) not a bug (3) environment (3) continuous integration (2) low priority (2) support (1)
Pull Request Labels
gated (2)

Dependencies

requirements.txt pypi
  • conan *
  • pre-commit *
.github/workflows/ci-check.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/ci-conan.yml actions
  • actions/cache v3 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • hendrikmuhs/ccache-action v1.2 composite
.github/workflows/ci-test-package-cmake.yml actions
  • ASzc/change-string-case-action v2 composite
  • actions/cache v3 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/citation.yml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v2 composite
  • dieghernan/cff-validator main composite
.github/workflows/documentation.yml actions
  • actions/cache v3 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • peaceiris/actions-gh-pages v3 composite
.github/workflows/codeql.yml actions
  • actions/cache v3 composite
  • actions/checkout v4 composite
  • actions/setup-python v4 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite