C++ dimensional-analysis

Open-source C++ projects categorized as dimensional-analysis

Top 6 C++ dimensional-analysis Projects

dimensional-analysis
  1. mp-units

    The quantities and units library for C++

    Project mention: Python type hints may not be not for me in practice | news.ycombinator.com | 2024-11-27

    I suspect C++ still comes the closest to what you’re asking for today, at least among mainstream programming languages.

    Matrix dimensions are certainly doable, for example, because templates representing mathematical types like matrices and vectors can be parametrised by integers defining their dimension(s) as well as the type of an individual element.

    You can also use template wizardry to write libraries like mp-units¹ or units² that provide explicit representations for numerical values with units. You can even get fancy with user-defined literals so you can write things like 0.5_m and have a suitably-typed value created (though that particular trick does get less useful once you need arbitrary compound units like kg·m·s⁻²).

    Both of those are fairly well-defined problems and the solutions available do provide a good degree of static checking at compile time.

    IMHO, the range question is the trickiest one of your three examples, because in real mathematical code there are so many different things you might want to constrain. You could define a parametrised type representing open or closed ranges of integers between X and Y easily enough, but how far down the rabbit hole do you go? Fractional values with attached precision/error metadata? The 572 specific varieties of matrix that get defined in a linear algebra textbook, and which variety you get back when you compute a product of any two of them?

    ¹ https://mpusz.github.io/mp-units/

    ² http://nholthaus.github.io/units/

  2. InfluxDB

    InfluxDB – Built for High-Performance Time Series Workloads. InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.

    InfluxDB logo
  3. UNITS

    a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.

    Project mention: Python type hints may not be not for me in practice | news.ycombinator.com | 2024-11-27

    I suspect C++ still comes the closest to what you’re asking for today, at least among mainstream programming languages.

    Matrix dimensions are certainly doable, for example, because templates representing mathematical types like matrices and vectors can be parametrised by integers defining their dimension(s) as well as the type of an individual element.

    You can also use template wizardry to write libraries like mp-units¹ or units² that provide explicit representations for numerical values with units. You can even get fancy with user-defined literals so you can write things like 0.5_m and have a suitably-typed value created (though that particular trick does get less useful once you need arbitrary compound units like kg·m·s⁻²).

    Both of those are fairly well-defined problems and the solutions available do provide a good degree of static checking at compile time.

    IMHO, the range question is the trickiest one of your three examples, because in real mathematical code there are so many different things you might want to constrain. You could define a parametrised type representing open or closed ranges of integers between X and Y easily enough, but how far down the rabbit hole do you go? Fractional values with attached precision/error metadata? The 572 specific varieties of matrix that get defined in a linear algebra textbook, and which variety you get back when you compute a product of any two of them?

    ¹ https://mpusz.github.io/mp-units/

    ² http://nholthaus.github.io/units/

  4. SI

    A header only C++ library that provides type safety and user defined literals for physical units (by bernedom)

  5. au

    A C++14-compatible physical units library with no dependencies and a single-file delivery option. Emphasis on safety, accessibility, performance, and developer experience. (by aurora-opensource)

  6. unlib

    a light-weight, header-only, dependency-free, C++14 library for ISO units

  7. Dimwits

    A compact C++ header-only library providing compile-time dimensional analysis and unit awareness (by njoy)

NOTE: The open source projects on this list are ordered by number of github stars. The number of mentions indicates repo mentiontions in the last 12 Months or since we started tracking (Dec 2020).

C++ dimensional-analysis discussion

Log in or Post with

C++ dimensional-analysis related posts

  • What's the point of std:monostate? You can't do anything with it

    1 project | news.ycombinator.com | 22 Jul 2024
  • Is it just mean, or is C# easier to learn than JavaScript or even PHP?

    2 projects | /r/dotnet | 6 Dec 2023
  • I'm a beginner making a library for unit conversion, contributions are welcome

    4 projects | /r/cpp | 21 Apr 2023
  • Why is this piece of code compiling with char as c-tor argument?

    2 projects | /r/cpp_questions | 7 Feb 2023
  • EzGz - An easy to use single header no dependency library for decompression of .gz archives written in modern C++ (probably faster than zlib)

    4 projects | /r/cpp | 15 Nov 2022
  • I got curious about units of measure in programming languages so I recreated xkcd/687.

    1 project | /r/xkcd | 24 May 2022
  • C++ for Mathematicians

    2 projects | /r/cpp | 2 Apr 2022
  • A note from our sponsor - InfluxDB
    www.influxdata.com | 23 May 2025
    InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now. Learn more →

Index

What are some of the best open-source dimensional-analysis projects in C++? This list will help you:

# Project Stars
1 mp-units 1,201
2 UNITS 998
3 SI 509
4 au 360
5 unlib 31
6 Dimwits 9

Sponsored
InfluxDB – Built for High-Performance Time Series Workloads
InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
www.influxdata.com

Did you know that C++ is
the 7th most popular programming language
based on number of references?