Skip to content

si-units: Add strongly-typed SI units

Jiwoong Lee requested to merge porce/ns-3-dev:si-units into master

Tracked by Issue 1042

Coherent use of units - dimensions, quantities, and scales - is imperative for the correctness of physics equations. Yet it is easy to fail to fulfill. One single mismatch invalidates simulation model and results. There are numerous incidents root-caused by type mismatches in industry, and possibly more yet to be discovered.

This commit invites compiler's assistance to this matter by introducing strongly-typed SI units that are popular in ns-3. The goal is to achieve API coherence; hence it becomes impossible to make mistakes.

Following strong types are supported:

Hz, kHz, MHz, GHz, THz
dB, dBm, pWatt, mWatt, Watt, dBm_per_Hz,
degree, radian

Following weak type aliases are supported:

dB_t, dBm_t, meter_t, ppm_t, ampere_t, joule_t, volt_t

Following constants are supported:

ONE_KILO, ONE_MEGA, ONE_GIGA, ONE_TERA, ONE_PETA

Design consideatrions are documented in si-units.rst.

Usages are demonstrated in a form of a unit test. See si-units-test-suite.cc

Tests:

  • Add a new test suite: si-units-test
> ./test.py -s si-units-test
Edited by Jiwoong Lee

Merge request reports