User: Password:
Subscribe / Log in / New account

A false midnight

A false midnight

Posted Mar 14, 2014 1:18 UTC (Fri) by Karellen (subscriber, #67644)
In reply to: A false midnight by pboddie
Parent article: A false midnight

"it's like treating every integer whose decimal representation ends with a zero as being false."

Or like treating every floating point value which happens to be an exact integer as false.

(Log in to post comments)

A false midnight

Posted Mar 14, 2014 17:37 UTC (Fri) by duelafn (subscriber, #52974) [Link]

First: I agree that it was a poor choice to make midnight False.

However, the comparison to a float where every int is false is not exactly a fair comparison since a datetime is always True. Compare instead to a Decimal implemented as a pair: (DecimalIntPart, DecimalFractionalPart). Then making the DecimalFractionalPart be False when the Decimal is an integer is much more reasonable:

if my_decimal.fractional_part: print("Is not an integer")

It, to me, makes the original implementation seem less "completely insane" and more "not the best choice".

Copyright © 2018, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds