On 2016-05-22, Ben Bacarisse <ben.use...@bsb.me.uk> wrote: > Jon Ribbens <jon+use...@unequivocal.co.uk> writes: ><snip> >> No, in Python integers are closed under the standard arithmetic >> operators (+ - * / % **) - except, since Python 3, for "/", which >> is now a special case. > > 2 ** -1 is 0.5 even in Python 2[*].
Haha, excellent, well found. I was wondering if there were any edge cases I was wrong about. I suppose ideally I would make it so that 2 ** -1 throws an exception or something. But of course this particular train has left the station a long time ago. > I agree with your general point (that floats should not pop up unbidden) > but I don't think you need to exclude the possibly that an operator can > do that. With perfect hindsight, I think I'd have had the integers > closed under operators +, -, *, //, % and (say) ^, whilst making it > clear that / and ** produce floats. There's no reason to see this as > being any less explicit that writing 1.0 as a way to make your intent to > use floats explicit. My fundamental point is that floats are surprising, so people should not be surprised by them arriving unbidden - and most of the time, there is no need at all for them to turn up unannounced. Making that occurrence more likely rather than less was a mistake. -- https://mail.python.org/mailman/listinfo/python-list