Ask Your Question
0

A bug on ceil function?

asked 2025-09-08 12:07:02 +0200

Ys1123 gravatar image

A following code

from math import ceil

val = (3**38 / (2*3 - 1) - 1) / 2
print(ceil(val) - val)

return

38/5

But this is weird since the value should be $< 1$ by the definition of the ceil function.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2025-09-08 16:33:47 +0200

Max Alekseyev gravatar image

updated 2025-09-08 18:10:55 +0200

from math import ceil imports ceil function from Python's math module. So this bug (probably related to an insufficient precision of the float number resulting from division of 3**38) has nothing to do with Sage.

If you want ceil function from Sage, use from sage.all import ceil instead.

edit flag offensive delete link more

Comments

Thank you, you're right. Then is this a bug of Python? Should I report this?

Ys1123 gravatar imageYs1123 ( 2025-09-08 17:02:51 +0200 )edit

It's up to you. However, I think it's not a bug but just an insufficient precision of the standard Python's float type, which you obtain as the result of division of two ints.

Max Alekseyev gravatar imageMax Alekseyev ( 2025-09-08 18:09:24 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-09-08 12:07:02 +0200

Seen: 13,975 times

Last updated: Sep 08