Skip to content

Commit

Permalink
Add unit symbol for every unit (#197)
Browse files Browse the repository at this point in the history
Usually, this is just the unit label. Exceptions:

- For Percent, we use `pct` instead of `%` (which would not work).
- For temperatures with "offset zero", we append `_qty` as an extra
  measure to avoid confusion: `degC_qty` and `degF_qty`.  (If users
  don't like this, they can define their own symbols!)

We also defer defining a symbol object for `Unos`, because
`::au::symbols::U` could also refer to [enzyme units] if we end up
supporting those later.  We'll have to think carefully about what the
library should do here.  In any case, it's fine to just defer it and
keep this present PR as "just the easy stuff".

Many symbols would be in danger of colliding with, e.g.,
`SingularNameFor`. For example, `bar` is both the symbol for `Bars` and
its singular name. For this reason --- and, because symbols introduce
many very short names! --- we add an extra namespace, `::au::symbols`.
Users should import symbols one at a time, as needed. For example, in a
`.cc` file:

```cpp
using ::au::symbols::m;
```

This makes it easy for anyone who runs across the `m` symbol to find its
definition.

Fixes #43.

[enzyme units]: https://en.wikipedia.org/wiki/Enzyme_unit
  • Loading branch information
chiphogg authored Dec 2, 2023
1 parent 0e7af22 commit cd9cccf
Show file tree
Hide file tree
Showing 102 changed files with 462 additions and 0 deletions.
5 changes: 5 additions & 0 deletions au/units/amperes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"

namespace au {

Expand All @@ -32,4 +33,8 @@ struct Amperes : UnitImpl<Current>, AmperesLabel<void> {
constexpr auto ampere = SingularNameFor<Amperes>{};
constexpr auto amperes = QuantityMaker<Amperes>{};

namespace symbols {
constexpr auto A = SymbolFor<Amperes>{};
}

} // namespace au
4 changes: 4 additions & 0 deletions au/units/bars.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "au/prefix.hh"
#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/pascals.hh"

namespace au {
Expand All @@ -34,4 +35,7 @@ struct Bars : decltype(Kilo<Pascals>{} * mag<100>()), BarsLabel<void> {
constexpr auto bar = SingularNameFor<Bars>{};
constexpr auto bars = QuantityMaker<Bars>{};

namespace symbols {
constexpr auto bar = SymbolFor<Bars>{};
} // namespace symbols
} // namespace au
4 changes: 4 additions & 0 deletions au/units/becquerel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/seconds.hh"

namespace au {
Expand All @@ -32,4 +33,7 @@ struct Becquerel : UnitInverseT<Seconds>, BecquerelLabel<void> {
};
constexpr auto becquerel = QuantityMaker<Becquerel>{};

namespace symbols {
constexpr auto Bq = SymbolFor<Becquerel>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/bits.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"

namespace au {

Expand All @@ -32,4 +33,7 @@ struct Bits : UnitImpl<Information>, BitsLabel<void> {
constexpr auto bit = SingularNameFor<Bits>{};
constexpr auto bits = QuantityMaker<Bits>{};

namespace symbols {
constexpr auto b = SymbolFor<Bits>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/bytes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/bits.hh"

namespace au {
Expand All @@ -33,4 +34,7 @@ struct Bytes : decltype(Bits{} * mag<8>()), BytesLabel<void> {
constexpr auto byte = SingularNameFor<Bytes>{};
constexpr auto bytes = QuantityMaker<Bytes>{};

namespace symbols {
constexpr auto B = SymbolFor<Bytes>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/candelas.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"

namespace au {

Expand All @@ -32,4 +33,7 @@ struct Candelas : UnitImpl<LuminousIntensity>, CandelasLabel<void> {
constexpr auto candela = SingularNameFor<Candelas>{};
constexpr auto candelas = QuantityMaker<Candelas>{};

namespace symbols {
constexpr auto cd = SymbolFor<Candelas>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/celsius.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "au/prefix.hh"
#include "au/quantity.hh"
#include "au/quantity_point.hh"
#include "au/unit_symbol.hh"
#include "au/units/kelvins.hh"

namespace au {
Expand All @@ -40,4 +41,7 @@ constexpr auto celsius_pt = QuantityPointMaker<Celsius>{};
"`celsius()` is ambiguous. Use `celsius_pt()` for _points_, or `celsius_qty()` for "
"_quantities_")]] constexpr auto celsius = QuantityMaker<Celsius>{};

namespace symbols {
constexpr auto degC_qty = SymbolFor<Celsius>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/coulombs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/amperes.hh"
#include "au/units/seconds.hh"

Expand All @@ -34,4 +35,7 @@ struct Coulombs : decltype(Amperes{} * Seconds{}), CoulombsLabel<void> {
constexpr auto coulomb = SingularNameFor<Coulombs>{};
constexpr auto coulombs = QuantityMaker<Coulombs>{};

namespace symbols {
constexpr auto C = SymbolFor<Coulombs>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/days.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/hours.hh"

namespace au {
Expand All @@ -33,4 +34,7 @@ struct Days : decltype(Hours{} * mag<24>()), DaysLabel<void> {
constexpr auto day = SingularNameFor<Days>{};
constexpr auto days = QuantityMaker<Days>{};

namespace symbols {
constexpr auto d = SymbolFor<Days>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/degrees.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/radians.hh"

namespace au {
Expand All @@ -33,4 +34,7 @@ struct Degrees : decltype(Radians{} * PI / mag<180>()), DegreesLabel<void> {
constexpr auto degree = SingularNameFor<Degrees>{};
constexpr auto degrees = QuantityMaker<Degrees>{};

namespace symbols {
constexpr auto deg = SymbolFor<Degrees>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/fahrenheit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "au/prefix.hh"
#include "au/quantity.hh"
#include "au/quantity_point.hh"
#include "au/unit_symbol.hh"
#include "au/units/kelvins.hh"

namespace au {
Expand All @@ -42,4 +43,7 @@ constexpr auto fahrenheit_pt = QuantityPointMaker<Fahrenheit>{};
"`fahrenheit()` is ambiguous. Use `fahrenheit_pt()` for _points_, or `fahrenheit_qty()` for "
"_quantities_")]] constexpr auto fahrenheit = QuantityMaker<Fahrenheit>{};

namespace symbols {
constexpr auto degF_qty = SymbolFor<Fahrenheit>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/farads.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/coulombs.hh"
#include "au/units/volts.hh"

Expand All @@ -34,4 +35,7 @@ struct Farads : decltype(Coulombs{} / Volts{}), FaradsLabel<void> {
constexpr auto farad = SingularNameFor<Farads>{};
constexpr auto farads = QuantityMaker<Farads>{};

namespace symbols {
constexpr auto F = SymbolFor<Farads>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/fathoms.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/feet.hh"

namespace au {
Expand All @@ -33,4 +34,7 @@ struct Fathoms : decltype(Feet{} * mag<6>()), FathomsLabel<void> {
constexpr auto fathom = SingularNameFor<Fathoms>{};
constexpr auto fathoms = QuantityMaker<Fathoms>{};

namespace symbols {
constexpr auto ftm = SymbolFor<Fathoms>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/feet.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/inches.hh"

namespace au {
Expand All @@ -33,4 +34,7 @@ struct Feet : decltype(Inches{} * mag<12>()), FeetLabel<void> {
constexpr auto foot = SingularNameFor<Feet>{};
constexpr auto feet = QuantityMaker<Feet>{};

namespace symbols {
constexpr auto ft = SymbolFor<Feet>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/furlongs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/miles.hh"

namespace au {
Expand All @@ -33,4 +34,7 @@ struct Furlongs : decltype(Miles{} / mag<8>()), FurlongsLabel<void> {
constexpr auto furlong = SingularNameFor<Furlongs>{};
constexpr auto furlongs = QuantityMaker<Furlongs>{};

namespace symbols {
constexpr auto fur = SymbolFor<Furlongs>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/grams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"

namespace au {

Expand All @@ -32,4 +33,7 @@ struct Grams : UnitImpl<Mass>, GramsLabel<void> {
constexpr auto gram = SingularNameFor<Grams>{};
constexpr auto grams = QuantityMaker<Grams>{};

namespace symbols {
constexpr auto g = SymbolFor<Grams>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/grays.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "au/prefix.hh"
#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/grams.hh"
#include "au/units/joules.hh"

Expand All @@ -35,4 +36,7 @@ struct Grays : decltype(Joules{} / Kilo<Grams>{}), GraysLabel<void> {
constexpr auto gray = SingularNameFor<Grays>{};
constexpr auto grays = QuantityMaker<Grays>{};

namespace symbols {
constexpr auto Gy = SymbolFor<Grays>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/henries.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/amperes.hh"
#include "au/units/webers.hh"

Expand All @@ -34,4 +35,7 @@ struct Henries : decltype(Webers{} / Amperes{}), HenriesLabel<void> {
constexpr auto henry = SingularNameFor<Henries>{};
constexpr auto henries = QuantityMaker<Henries>{};

namespace symbols {
constexpr auto H = SymbolFor<Henries>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/hertz.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/seconds.hh"

namespace au {
Expand All @@ -32,4 +33,7 @@ struct Hertz : UnitInverseT<Seconds>, HertzLabel<void> {
};
constexpr auto hertz = QuantityMaker<Hertz>{};

namespace symbols {
constexpr auto Hz = SymbolFor<Hertz>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/hours.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/minutes.hh"

namespace au {
Expand All @@ -33,4 +34,7 @@ struct Hours : decltype(Minutes{} * mag<60>()), HoursLabel<void> {
constexpr auto hour = SingularNameFor<Hours>{};
constexpr auto hours = QuantityMaker<Hours>{};

namespace symbols {
constexpr auto h = SymbolFor<Hours>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/inches.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "au/prefix.hh"
#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/meters.hh"

namespace au {
Expand All @@ -34,4 +35,7 @@ struct Inches : decltype(Centi<Meters>{} * mag<254>() / mag<100>()), InchesLabel
constexpr auto inch = SingularNameFor<Inches>{};
constexpr auto inches = QuantityMaker<Inches>{};

namespace symbols {
constexpr auto in = SymbolFor<Inches>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/joules.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/meters.hh"
#include "au/units/newtons.hh"

Expand All @@ -34,4 +35,7 @@ struct Joules : decltype(Newtons{} * Meters{}), JoulesLabel<void> {
constexpr auto joule = SingularNameFor<Joules>{};
constexpr auto joules = QuantityMaker<Joules>{};

namespace symbols {
constexpr auto J = SymbolFor<Joules>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/katals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "au/quantity.hh"
#include "au/unit_symbol.hh"
#include "au/units/moles.hh"
#include "au/units/seconds.hh"

Expand All @@ -34,4 +35,7 @@ struct Katals : decltype(Moles{} / Seconds{}), KatalsLabel<void> {
constexpr auto katal = SingularNameFor<Katals>{};
constexpr auto katals = QuantityMaker<Katals>{};

namespace symbols {
constexpr auto kat = SymbolFor<Katals>{};
}
} // namespace au
4 changes: 4 additions & 0 deletions au/units/kelvins.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "au/quantity.hh"
#include "au/quantity_point.hh"
#include "au/unit_symbol.hh"

namespace au {

Expand All @@ -34,4 +35,7 @@ constexpr auto kelvin = SingularNameFor<Kelvins>{};
constexpr auto kelvins = QuantityMaker<Kelvins>{};
constexpr auto kelvins_pt = QuantityPointMaker<Kelvins>{};

namespace symbols {
constexpr auto K = SymbolFor<Kelvins>{};
}
} // namespace au
Loading

0 comments on commit cd9cccf

Please sign in to comment.