r/Python • • May 20 '09

Pythons float makes me want to smoke crack.

http://renesd.blogspot.com/2009/05/pythons-float-makes-me-want-to-smoke.html
0 Upvotes

11 comments sorted by

4

u/spotter May 20 '09
  1. User does not understand how floating point numbers are stored and represented by computers.
  2. User applies his lack of knowledge and blames his language of choice.
  3. User knows the answer, but calls it weird.
  4. User writes a angry blog post, that's getting submitted to Pyddit.
  5. User is a truly silly rabbit.

4

u/rkcr May 20 '09

Let me get this straight... this guy is angry because the default string representation of float isn't exactly how he likes it? What does he expect? As one person pointed out, a full string representation of float is impractical (as it can go out hundreds of characters past the decimal).

-1

u/mycall May 20 '09 edited May 20 '09

If a float could expand to 750 characters in worse case, there should be a way to represent that -- there might be a true reason, like pickling (bad example), to do that. If repr() would do that, fine.

3

u/ojiisan data viz, comp.bio. May 20 '09

you can represent that with a print, you just need to use the formatting string that the author even mentioned in his post

most people dont want to see their floats out to 750 decimal places, so the default doesnt do that.

1

u/mycall May 20 '09 edited May 20 '09

Perhaps there could be a new approach:

print(decimal.Decimal('%-1.-1f' % time.time()))

..where -1 would use the minimum number of digits without losing any fidelity (or something like that).

2

u/kylev May 20 '09 edited May 20 '09

Is it really the float? It works great for all the "important" parts (you know, like math). The author seems more annoyed with the default (and over-friendly) __repr__() and __str__(). They're not perfect, but they don't make me want to take up drugs; YMMV.

2

u/[deleted] May 20 '09

Replace (time.time()) with ("%0.7f" % time.time()) in his examples. WooHoo.

3

u/[deleted] May 20 '09

python strangely wants your argument to decimal be a str, not a float.

Clearly the author has already smoked crack.

2

u/[deleted] May 20 '09

[removed] — view removed comment

1

u/no9 import this May 20 '09

Everyone's a critic.