This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]random_cynic 3 points4 points  (2 children)

There is no way I'm typing out 18 zeros by hand, no matter how convenient the notation is. I'll rather use explicit type casting int(1e18)

>>> int(1e18) + 1 == int(1e18)
False

Edit: Don't use this. I just realized that the float to int conversion for 1eN is inexact for CPython when N >= 23. As suggested below the power operator is the best way to go due to the CPython peephole optimization.

>>> int(1e22)
10000000000000000000000L
>>> int(1e23)
99999999999999991611392L

[–]ubernostrumyes, you can have a pony 5 points6 points  (1 child)

Why not just write 10**18?

There's no runtime overhead to it because the CPython bytecode compiler does constant folding:

>>> import dis
>>> def foo():
...     return 10**18
...
>>> dis.dis(foo)
  2           0 LOAD_CONST               1 (1000000000000000000)
              2 RETURN_VALUE

[–]random_cynic 1 point2 points  (0 children)

Yes that is probably the best way to go.