Ask Your Question

Revision history [back]

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.

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)