[Python-Dev] Mixing float and Decimal -- thread reboot (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Wed Mar 24 12:47:26 CET 2010
- Previous message: [Python-Dev] Mixing float and Decimal -- thread reboot
- Next message: [Python-Dev] Mixing float and Decimal -- thread reboot
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Steven D'Aprano wrote:
On Wed, 24 Mar 2010 08:51:36 pm Mark Dickinson wrote:
I don't see how it can be so. Aren't all of those entries garbage? To compute a histogram of results for computations on a series of cases would you not have to test each result for NaN-hood, then hash on a proxy such as the string "Nan"? Not necessarily -- you could merely ignore any key which is a NaN, or you could pass each key through this first: def internnan(x, nan=float('nan')): if math.isnan(x): return nan return x thus ensuring that all NaN keys were the same NaN.
Interning NaN certainly seems like it should be sufficient to eliminate the set/dict membership weirdness.
That is, make it so that the first two lines of the following return True, while the latter two lines continue to return False:
float("nan") is float("nan") False dec("nan") is dec("nan") False float("nan") == float("nan") False dec("nan") == dec("nan") False
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] Mixing float and Decimal -- thread reboot
- Next message: [Python-Dev] Mixing float and Decimal -- thread reboot
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]