Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4174

Integer Division

$
0
0

5 posts

hstehling (hanno) wrote:

Hi,

I just stumbled over some unexpected behaviour and thought I'd share it here.

Background: The standard division operator / behaves differently in python 2 and 3. While it performs an integer division in python 2 if both operands are integers, it always performs a true division in python 3.

Now RhinoPython is Python 2.7, so I thought it should behave the "old" way and did a quick test (on SR6):

run_division.py:

import import_division
print 1/3

import_division.py:

print 1/3

Running run_division.py gave me the following output:

0
0.333333333333

So apparently the directly run script uses "new division" while the imported script uses "old division". This is unexpected to say the least. Tested it on two machines. So if you are getting strange results, have a look at your divisions...

Best

Hanno


Viewing all articles
Browse latest Browse all 4174

Latest Images

Trending Articles



Latest Images