Or perhaps this is better:

>>> def interval(x,n):
...  m=10**-n
...  i = int(x/m) # how many m in x?
...  a = i*m
...  if a == x: return x, x
...  return (a, a+m) if x > 0 else (a, a-m)
...
>>> interval(.37512,3)
(0.375, 0.376)
>>> interval(.375,3)
(0.375, 0.375)

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to