3 ms·
When given two integers pretty much any language will return an integer (so 1/2 = 0). In Python 2.6, if one of the arguments is a float you'll get a float resu
by tvon 17y ago
When given two integers pretty much any language will return an integer (so 1/2 = 0).
In Python 2.6, if one of the arguments is a float you'll get a float result, the same is true for Ruby 1.8.
The new behavior is to return a float even if two integers are passed.
- dreish 17y agoWell, not exactly "pretty much any language": Common Lisp, Scheme, Arc, Clojure, Haskell, Perl, and SQL all return either 1/2 or 0.5. I'm sure there are plenty of others I'm not familiar with that behave the same way.
- tvon 17y agoGood point. I was thinking of the C-based languages, though to be honest I'm not sure all of them behave in the same way. I should have been more careful talking about languages, especially around here...