[Python-ideas] SI scale factors in Python
Ken Kundert
python-ideas at shalmirane.com
Thu Aug 25 04:54:41 EDT 2016
> Question, though: What happens with exa-? Currently, if the parser
> sees "1E", it'll expect to see another number, eg 1E+1 == 10.0. Will
> this double meaning cause confusion?
Allow me to refine my answer to this question ...
Yes, that is definitely problematic. I see two possible solutions.
1. Limit ourselves to the common scale factors:
T, G, M, k, _, m, u, n, p, f, a
2. Or accept X in lieu of E. After all, the e is silent anyway. Thus, on input
we accept ...
1Y -> 1e+24
1Z -> 1e+21
-> 1X -> 1e+18 <- only difference
1P -> 1e+15
1T -> 1e+12
1G -> 1e+09
1M -> 1e+06
1k -> 1e+03
1_ -> 1e+00
1m -> 1e-03
1u -> 1e-06
1n -> 1e-09
1p -> 1e-12
1f -> 1e-15
1a -> 1e-18
1z -> 1e-21
1y -> 1e-24
But on output we use ...
1Y -> 1e+24 optional
1Z -> 1e+21 optional
-> 1E -> 1e+18 optional
1P -> 1e+15 optional
1T -> 1e+12
1G -> 1e+09
1M -> 1e+06
1k -> 1e+03
1_ -> 1e+00
1m -> 1e-03
1u -> 1e-06
1n -> 1e-09
1p -> 1e-12
1f -> 1e-15
1a -> 1e-18
1z -> 1e-21 optional
1y -> 1e-24 optional
The optional scale factors are unfamiliar to most people, and if used might
result in harder to read numbers. So I propose that '%r' only outputs the common
scale factors, and %R outputs all the scale factors. Or we can use '#' in the
format string to indicate the 'alternate' form should be used, in this case
'alternate' means that the extended set of scale factors should be used.
-Ken
More information about the Python-ideas
mailing list