YADTR (Yet Another DateTime Rant)

Chris Angelico rosuav at gmail.com
Wed Mar 26 10:12:41 EDT 2014


On Thu, Mar 27, 2014 at 1:02 AM, Antoon Pardon
<antoon.pardon at rece.vub.ac.be> wrote:
> There is a difference between how people say things and what is useful.
> I remember when I was studying logarithms, a negative number like -5.73
> was written down as ̅6.27 (with a bar only over the six). That notation
> had the advantage that the part after the decimal point stayed the same
> if you added or subtracted whole numbers. Even if that would change the
> sign.

That's highly significant with logs, especially when you're working
with base 10 logs.

>>> math.log10(1234)
3.091315159697223
>>> math.log10(12340)
4.091315159697223
>>> math.log10(123400)
5.091315159697223
>>> math.log10(1234000)
6.091315159697223
>>> math.log10(12.34)
1.0913151596972228
>>> math.log10(1.234)
0.09131515969722287
>>> math.log10(.1234)
-0.9086848403027772
>>> math.log10(.01234)
-1.9086848403027772

By showing those last ones as 1̅.091... and 2̅.091..., you emphasize
the floating-point nature of the data: everything after the decimal is
the mantissa, and everything before the decimal is the exponent. I
can't say for sure as I don't really use that, but I can imagine that
there might be something similar with dates and times - it's three
days ago at 2:51, not two days and 21:09 ago.

Or maybe it's just "print it out in a way that more closely matches
the internal representation, to simplify debugging" :)

ChrisA



More information about the Python-list mailing list