IronPython calculation methods

Hello,

do anyone know why IronPython don’t calculate given integers the proper way? For exact result I has to convert the integers to floats.
Unbenannt

Hi, you can use from __future__ import division to get the behavior you are looking for

Ok, thanks. But from my point of view it is a REAL BIG BUG. I tried it in python 3 and it works properly.

Well… that is why they changed it for Python 3, despite the fact that it broke a lot of peoples code, and it is a big enough feature to make the headlines on python.org (item 3 in the central box). In modern python you have to use the integer division operator \\ to get this behaviour.

The python 2 behaviour makes sense if you think like a software compiler in terms of data types : applying an operator (division) to two integers produces another integer. It is called ‘integer division’ and is common to many programming languages including C, from which python is derived. However it doesnt make sense if you think like a mathematician and as Python is often used as a scripting language in other software (such as Rhino) or a first programming language this trips a lot of people up.

2 Likes