unit type for addition to std lib [was Re: D Language 2.0]

SiegeLord ps335 at cornell.edu
Wed Jan 20 07:29:35 PST 2010


Simen kjaeraas Wrote:

> On Wed, 20 Jan 2010 03:47:58 +0100, BCS <none at anon.com> wrote:
> 
> > Hello SiegeLord,
> >
> >> BCS Wrote:
> >>
> >>>> Also all of the imperial units that I don't care about, as well as
> >>>> the more obscure physical units.
> >>>>
> >>> My lib has every SI unit I could fine and all the units I found that
> >>> I recognised. The current vertion can have a new unit added as a
> >>> single line of code.
> >>>
> >> SI has 7 base units, your library has only 5 of them. You are missing
> >> luminosity (candellas) and amounts (moles).
> >>
> >
> > They would be easy to add.
> >
> > That said All the other type systems (CGS, MKS, imperial, etc.) only  
> > have those 5 and I find claiming the the last two are base units just a  
> > bit silly (candelas are defined in terms of power, stradians and an  
> > arbitrary curve and moles are a count). I left them out in protest but  
> > I'll add them if anyone cares enough to make much of an issue of it.
> 
> I can see reasons to add the Candela (though it is simply a function of
> other units, it is not as simple as an SI derived unit), but the mole is
> merely the Avogadro constant.
> I'd vote for this solution:
> 
> enum Mole = 6.022_141_79e23;
> enum MolarMass = OfType.gram( 1 / Mole );
> 
> -- 
> Simen

Avogadro's number is not know precisely, and because of that very reason the unit of mole is used. It is not even known precisely enough to fill out the 15 digits of precision that double type provides, which just makes it unacceptable as a hard-coded constant (unlike say, pi).

Secondly, defining it as a constant like that you are robbing the user of 9 digits of precision for no good reason. With that approach, amounts like 1.234567 mol are not representable in a double, almost as bad as using a float! Chemists will not be pleased.

Thirdly, it's an SI unit. If you claim that the library supports the SI units, then you should do that. There are 7 base SI units, your personal objections non-withstanding. MKS and CGS do exist, but I've never seen them used in Chemistry in my experience. Similarly, I've never seen chemists converting moles to the numbers of atoms they represent.

On a related note, and as a large limitation of this library, there are these things called 'natural' units, which are SI derived units with some complex constant in front. See here (http://en.wikipedia.org/wiki/Natural_units#.22Natural_Units.22_.28Particle_Physics.29 ) for example. It is impractical to treat them as derived units, primarily due to precision losses, so they must also be base units. Since there's an innumerable number of these (scientifically) valid units, it really should be possible to define custom units by the user somehow.

-SiegeLord




More information about the Digitalmars-d mailing list