RFC: Units of measurement for D (Phobos?)
David Nadlinger via Digitalmars-d
digitalmars-d at puremagic.com
Tue Mar 15 17:15:39 PDT 2016
On Tuesday, 15 March 2016 at 14:46:30 UTC, D.Enguiyen wrote:
> Is it able to manage quantities with a non-linear
> transformations, for example when dealing with octet and byte ?
>
> (1024)!"byte" == 1!"kbyte";
There are no non-linear transformations going on here, following
usual math terminology.
If your question is whether unit conversions are possible with
non-power-of-ten factors, the answer is an empathic "yes" – the
scale factors could even be determined at run-time! The most
basic solution would be to define a scaled unit like this:
enum kibyte = scale!(byte, 1024, "kibibyte", "kiB");
You would probably want to define a power-of-two PrefixSystem
though.
(http://klickverbot.at/code/units/std_units.html#PrefixSystem)
— David
More information about the Digitalmars-d
mailing list