Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I just tested int(-7/4) on sagecell.sagemath.org and it returns -1 as expected. This server is now running Sage 7.2, so perhaps there is an issue in 7.1.

The .round() option only applies to half integers, as indicated in the documentation. For example, (-3/2).round("toward") returns -1 while (-3/2).round("away") returns -2.

click to hide/show revision 2
No.2 Revision

I just tested int(-7/4) on sagecell.sagemath.org and it returns -1 as expected. This server is now running Sage 7.2, so perhaps there is an issue in 7.1.

The .round() option only applies to half integers, as indicated in the documentation. For example, (-3/2).round("toward") returns -1 while (-3/2).round("away") returns -2.

As suggested by @calc314, here is a function that rounds toward zero:

def f(x):
    if x > 0:
        return floor(x)
    else:
        return ceil(x)