AngouriMath

Navigation

← Back to list of members

ToSymPy

 Method (no overloads)

Remarks

SymPy has no symbolic round -- `RoundFunction` is an abstract base and
raises, and `.round()` is a method on a concrete number rather than a
function of an expression. So this is built out of what SymPy does have.

It is deliberately not `sympy.floor(x + 1/2)`, which is the obvious
translation and is wrong at every tie: that sends 1/2 to 1 and 5/2 to 3,
where rounding half to even gives 0 and 2. The correction below is exactly
the tie case -- when the fractional part is a half and the candidate is odd,
step down to the even neighbour -- and was checked against SymPy's own
`Rational.round()` on ties, non-ties and negatives.

























Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 1953 pages online