Robotico.Units 0.1.0

.NET 10 C# xUnit License: MIT

Robotico.Units

SI quantity for calculation. SiUnit is a readonly struct: a double magnitude and seven float powers of the SI base units. Unit converts a reading into that quantity. The library has no database and no other package dependencies.

The C twin is robotico-units-c.

The value

Field Type Meaning
Value double Magnitude in coherent base units
Second float Exponent of the second
Metre float Exponent of the metre
Kilogram float Exponent of the kilogram
Ampere float Exponent of the ampere
Kelvin float Exponent of the kelvin
Mole float Exponent of the mole
Candela float Exponent of the candela

A prefix is folded into the magnitude. 3 km is Value 3000 and Metre 1. Temperature is kelvin. 20 °C is Value 293.15 and Kelvin 1. A radian has every power at 0.

Arithmetic

Each operation returns a new value.

  • Add and subtract keep the powers. The powers match when each pair differs by less than 0.000001. A double, or a decimal converted to double, joins the magnitude only when every power is zero. An int, long, float, uint, or ulong reaches the double operators through the language conversion.
  • Multiply multiplies the magnitudes and adds the powers. Divide divides the magnitudes and subtracts the powers. A number divided by a quantity flips every power.
  • Pow multiplies every power by the exponent. A negative magnitude takes a whole-number exponent. Zero to a power at or below zero is refused.
  • Negate changes the sign of the magnitude.
  • <, >, <=, and >= order the magnitudes when the powers match.
  • == is exact on the stored fields, so the value can be a dictionary key.

A decimal has named methods (Add, Subtract, Multiply, Divide, Pow) and no operator. An operator for both double and decimal would make an integer literal ambiguous.

CoherentName reads a name such as newton from the powers. Becquerel shares the powers of hertz. Sievert shares the powers of gray.

Conversion

Unit holds a symbol, a dimension, a scale, and an offset. A reading becomes a coherent quantity as reading * scale + offset. FromCoherent reverses that. A difference uses the scale only, so 10 °C of change is 10 K and 18 °F of change is 10 K.

Celsius and Fahrenheit are the units with an offset. A prefix, a product, and a quotient are refused while an offset is present. Mass prefixes attach to the gram, so a milligram is a prefixed gram and the kilogram stays the coherent unit. SiPrefix runs from quecto through quetta. SiPrefix.None is the identity.

Two units are equal when the scale, the offset, and the dimension match. The symbol is a name, so kn and nmi/h compare equal.

NamedUnits is the catalog: length, speed, time, mass, force, pressure, energy, power, temperature, angle, area, volume, frequency, amount, electric and magnetic units, candela, lux, and density. It includes the mile, the knot, the parsec, and the Julian light-year. A femto-parsec is NamedUnits.Parsec.WithPrefix(SiPrefix.Femto).

Defined factors are exact: the 2019 SI constants, the 1959 yard and pound, the nautical mile, and the conventional atmosphere, calorie, and horsepower. Codata2022 holds measured values with their standard uncertainties: the dalton, the hartree, the Bohr radius, G, and the electron mass.

Decibel is not a linear unit. It converts a power ratio, an amplitude ratio, dBm, and dBW. 0 dBm is 1 mW.

Historical

Historical is a second catalogue. Each entry is a SourcedUnit: a Unit, a stable id, a place, a named period, and the statute or publication that fixed the scale. ToCoherent returns an ordinary SiUnit and drops the citation. NamedUnits stays the living catalogue, so the 1959 foot remains 0.3048 m.

An exact scale has no uncertainty. A reconstructed scale stores the published spread, or half the last stated digit when the source gives no spread. A derived unit is an exact ratio of its base, and the uncertainty follows that ratio. A year is a search bound on the period. It does not select a different factor.

The dated exact group holds the US survey foot of 1893 (1200/3937 m) and the survey chain, link, rod, furlong, mile, and acre; the French myriametre of 1795 (104 m); the Réaumur, Rømer, and Delisle scales on the modern ice and steam points; and the litre of the 1901 CGPM, stored as 1.000028 dm³ because the 11th CGPM called the difference about 28 parts in 106.

Egypt is the Old Kingdom royal cubit from Petrie (1883), 20.62 +/- 0.01 inch. The digit, palm, hand, fist, double palm, spans, sacred cubit, remen, small cubit, khet, iteru, and setjat are exact ratios of that cubit. The khar is two thirds of one cubic royal cubit, from the Rhind Mathematical Papyrus. Rome is Hultsch's pes monetalis, 0.2957 m, with the digitus through the mile, the leuga, the actus quadratus, and the iugerum. The French royal measures are the 1799 law: one metre is 443.296 lignes of the Toise du Pérou, and the pouce, pied, toise, perches, leagues, arpents, pinte, and muid follow from that ligne. Japan is the 1891 shaku-kan act: the shaku is 10/33 m, the kan is 15/4 kg, and the sho is 2401/1331000 m³. China is the market system of 16 February 1929: the chi is 1/3 m, the jin is 1/2 kg, and the sheng is 1 L. The Russian imperial system of 4 June 1899 fixes the arshin at 0.7112 m and the funt at 0.40951241 kg. Its vedro and garnets are the statute's weights of water, stored as mass.

The Attic foot is Hultsch's 308.3 mm, with the daktylos, palaiste, pechus, orgyia, plethron, and stadion. Prussia, by the order of 16 May 1816, takes the foot as 139.13 Paris lines, then the zoll, linie, elle, lachter, ruthe, and mile. The Austrian law of 23 July 1871 fixes the Viennese klafter at 1.896484 m. The Swiss concordat of 17 August 1835 fixes the foot at 3/10 m and the pound at 1/2 kg. The Baden order of 1810 fixes the same foot. The Danish law of 1875 fixes the foot at 0.3138535 m. The Swedish ordinance of 1855 fixes the foot at 0.29690 m.

The Wurttemberg order of 1806 fixes the foot at 127 Paris lines, and the morgen is 384 square rods. The Zollverein decision of 1854 fixes the pound at 500 g. The Saxon standard of 1858 fixes the Leipzig foot at 125.537 Paris lines. The Hamburg notice of 2 April 1869 prints the foot as 286.57 mm. The Mecklenburg-Schwerin notice of 19 April 1869 prints the foot as 28.6488 cm and the pound as 500.001 g. The Mecklenburg-Strelitz notice of 4 May 1869 prints the duodecimal foot as 0.31385354 m and the pound as 0.6 kg. The Hesse law of 10 December 1817 fixes the zoll at 1/40 m, so the werkfuss of 12 zoll is 0.3 m and the pound is 500 g. The Baden comparison of 25 January 1870 prints the ell, the klafter, the rod, a morgen of 3600 m², a sester of 15 litres, and a pound of 500 g. The Braunschweig law of 30 March 1837 fixes the werkfuss at 126.5 Paris lines. The Nassau comparison of 13 May 1869 fixes the werkfuss at 0.3 m and the field rod at 5 m. The Hanover comparison of the same day prints the foot as 0.29209 m. The Frankfurt foot is 126 1/6 Paris lines and the ell is 242.616 Paris lines. The Neuchatel regulation of 1805 fixes the land foot at 130 Paris lines. Kurhessen takes the werkfuss as 11 Rhenish inches and the cadastral foot as 126.3 Paris lines. The Schleswig-Holstein comparison of 13 May 1869 prints the foot as 0.28657 m and the ell as 0.57314 m. de Gelder's 1807 measurement of the Leiden copy gives the Rijnland foot as 0.3139465 m.

The Spanish royal order of 9 December 1852 fixes the Burgos vara at 0.835905 m, with the pie, the pulgada, and the fanega of 9216 square varas. The same order prints the other provincial standards: Albacete 837 mm and 458 g, Alicante 912 mm and 533 g, Almeria 833 mm, Barcelona cana 1555 mm with a trade pound of 400 g and a medicinal pound of 300 g, Castellon and Valencia 906 mm and the Castellon pound 358 g, Ciudad-Real and Jaen 839 mm, Gerona cana 1559 mm and 400 g, Huesca 772 mm, Lerida half-cana 778 mm and 401 g, Logrono the Albacete vara, Lugo 855 mm and 573 g, Madrid and Coruna 843 mm with the Coruna pound 575 g, Palma half-cana 782 mm and 407 g, Pamplona 785 mm and 372 g, Teruel 768 mm and 367 g, Zaragoza 772 mm and 350 g, Caceres 456 g, Orense 574 g, and Pontevedra 579 g. The Portuguese decree of 2 May 1855 fixes the metric league at 5000 m.

The Chilean law of 29 January 1848 prints a metric value for each old measure, including a vara of 0.836 m and a pie of 0.279 m. Senillosa's 1835 comparison gives the Buenos Aires vara as 0.8666 m. The Mexican regulation of 20 February 1896 fixes the vara at 0.838 m. The Polish decree of 13 June 1818, in force in 1819, fixes the ell at 576 mm, the pound at 405 g, and the quart at 1 litre. The New Granada law of 26 May 1836 fixes the vara at 8 decimetres. The Nicaragua law of 17 September 1857 fixes the foot at 28 cm. The Cuban prontuario of 1862 states the vara as 0.848 m. The Costa Rica table of 1885 states the vara as 83.600 cm.

The French decree of 12 February 1812 sets the retail toise at 2 m, the foot at one sixth of that toise, the aune at 12 dm, and the pound at 500 g. The Greek decree of 28 September 1836 names the metre the royal pechus and fixes the oka at 1280 g. The Ottoman kanunname of 26 September 1869 names the metre the decimal arsin and the 10 km the fersah. The Thai conversion of 1923 fixes the wa at 2 m and the baht at 15 g.

Muscovy stays the pre-Petrine printed arshin stated as 72 cm, the official sazhen, verst, and boundary verst, the body sazhens stated to the centimetre, the pre-arshin lokot of 51 cm, the land rectangles of the official sazhen, and the late-17th-century grivenka stated as 409.512 g. The rye chetvert is a mass of rye, at 4, 6, and 8 pud for the three official periods. A local measure with no statute and no single published central value has no entry. A seasonal hour needs a date and a latitude. Gaussian, esu, and emu units change the field equations, so they are not a scale on the seven SI powers.

SiUnit speed = NamedUnits.Knot.ToCoherent(12d);
double miles = NamedUnits.Mile.FromCoherent(NamedUnits.Kilometre.ToCoherent(10d));
SiUnit room = NamedUnits.Celsius.ToCoherent(20d);
SiUnit rise = NamedUnits.Celsius.DifferenceToCoherent(10d);
Unit femtoParsec = NamedUnits.Parsec.WithPrefix(SiPrefix.Femto);

Build

dotnet test robotico-units.slnx

No packages depend on Robotico.Units.

.NET 10.0

  • No dependencies.

Version Downloads Last updated
0.1.0 1 11/07/2026