kshitij10496 / gh-notifier

Desktop notifier for all your "social" GitHub notifications
MIT License
20 stars 10 forks source link

Compatibility Issues: ceil function #2

Closed kshitij10496 closed 8 years ago

kshitij10496 commented 8 years ago

There is a difference between the type of object returned by ceil method in Python2 and Python3.

In Python2, a float is returned

In []: from math import ceil
In []: ceil(15/10)
Out[]: 1.0
In []: ceil(15/10.0)
Out[]: 2.0

While in Python3, an int is returned

In []: from math import ceil
In []: ceil(15/10)
Out[]: 2

This is due to an interesting feature (issue) of Python2:

In Python 2.x : int/int --> int and int/float --> float In Python 3.x : int/int can result in a float

Ping @Arafatk !

zorroblue commented 8 years ago

So it would be better if we use int(ceil(15/10.0)) right?

kshitij10496 commented 8 years ago

So it would be better if we use int(ceil(15/10.0)) right?

This approach seems to be the most trivial fix to the issue for now. However, I feel this conceals the actual bug with portability. So, I would like a bit more research done on this.

P.S: Try from __future__ import division and executing the Python2 block.

zorroblue commented 8 years ago

@Arafatk Wont int(num)+2 fail for whole numbers? :)

int(5)+2 gives 7 while we want 6.

kshitij10496 commented 8 years ago

You are correct @zorroblue

@Arafatk : We need the ceil function for this particular reason.

arafatkatze commented 8 years ago

I was wondering if we could use

from __future__ import division
from math import ceil 
print (int(ceil(15/10)))

As that would give identical results for both python 2 and 3.

kshitij10496 commented 8 years ago

@Arafatk Yeah That would be cool ! :smile:

kshitij10496 commented 8 years ago

Fixed by #1