I made a modification so  it can take 1, 3, 4, ... number of operands
nicely.

def symround(x, ndigits=0):
   if hasattr(x,'operator') and x.operator():
      o = map( lambda y : symround(y,ndigits=ndigits) , x.operands() )
      r = o[0]
      for i in xrange(1,x.nops()):
          r = x.operator()(r,o[i])
      return r
   try:
      r = round(x,ndigits=ndigits)
      if r == x: return x
      else: return r
   except TypeError:
      return x

Then extra 'if r == x' check was introduced to avoid transformation of
unrounded ints into floats (avoiding 2x to 2.0x).

I may be ugly in terms of efficiency, but where I need it, it is a
perfect workaround.

Thanks,
Cristóvão Sousa

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to