Re: [Python-Dev] functions vs methods (was Re: trunc())

New idea: * Drop the existing second argument for round. * Fold ceil(), floor(), trunc(), and round() into a single function: def round(x, mode=): if mode==CEIL: return math.ceil(x) elif mode==FLOOR: return math.floor(x) elif mode==TRUNC: return math.floor(x) if x>0 else math.ceil(x) elif mode==ROUND_TO_EVEN: . . . Maybe we don't need a separate function and magic method for every possible rounding mode. Also, I think there was some discussion of changing round() to use statistician's rounding. We might as well make it explicit that this is the new default. Raymond P.S. One place to attach the constants is to the function object, so we would write: x = round(3.1) # ROUND_TO_EVEN x = round(3.1, round.CEIL) . . .
participants (1)
-
Raymond Hettinger