[Python-ideas] real numbers with SI scale factors
Steven D'Aprano
steve at pearwood.info
Tue Aug 30 09:41:10 EDT 2016
On Mon, Aug 29, 2016 at 08:48:55PM -0700, Ken Kundert wrote:
> >>> print(d_sun.to(u.kpc))
> 4.850441695494146e-09 kpc
>
> I can see where this can be helpful at times, but it kind of goes against the
> spirit of SI scale factors, were you are generally expected to 'normalize' the
> scale factor (use the scale factor that results in the digits presented before
> the decimal point falling between 1 and 999). So I would expected
>
> d_andromeda = 780 kpc
> d_sun = 4.8504 upc
Let me see if I get this straight... you *explicitly* asked for the
distance to the sun in kpc (kiloparsecs), but you expected a result in
µpc (microparsecs)?
When you ask the waiter for a short black, do you get upset that
he doesn't bring you a latte with soy milk? *wink*
I can see that such a normalising function would be useful, but I don't
think it should be the default. (If I ask for millimetres, I want
millimetres, not gigametres.) I've written and used code like that for
bytes, it makes sense to apply it to other measurement units. But only
if the caller requests normalisation, never by default.
I don't think there is any such general expectation that values should
be normalised in that way, and certainly not that your conversion
program should automatically do it for you. For example, see this list
of long-lived radioactive isotopes:
http://w.astro.berkeley.edu/~dperley/areopagus/isotopetable.html
Values above 650,000,000,000 (650e9) years are shown in "scientific
format", not "engineering format", e.g. Selenium-82 is given
as 1.1 x 10^20 rather than 110 x 10^18.
Likewise:
http://www.nist.gov/pml/data/halflife-html.cfm
displays a range of units (minutes, hours, days) with the base value
ranging up to over ten thousand, e.g. Ti-44 is shown as 22154 ± 456
days. This is NIST, which makes it pretty official. I don't think
there's any general expectation that values should be shown in the range
1 to 999. (Perhaps in certain specialist areas.)
--
Steve
More information about the Python-ideas
mailing list