Every line of 'python divide round up' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
1 def divide(dividend, divisor): 2 if not divisor: 3 return 4 5 current_sum = 0 6 quotient = 0 7 while current_sum <= dividend: 8 quotient += 1 9 current_sum += divisor 10 11 return quotient - 1
4 def round_down(v): 5 return (int(v[0]), int(v[1]))
631 def rpy_round(number, ndigits): 632 # Algorithm copied directly from CPython 633 634 if number == 0 or rfloat.isinf(number) or rfloat.isnan(number): 635 return number 636 637 # Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x 638 # always rounds to itself. For ndigits < NDIGITS_MIN, x always 639 # rounds to +-0.0. 640 if ndigits > NDIGITS_MAX: 641 return number 642 elif ndigits < NDIGITS_MIN: 643 # return 0.0, but with sign of x 644 return 0.0 * number 645 646 # finite x, and ndigits is not unreasonably large 647 z = rfloat.round_double(number, ndigits) 648 if rfloat.isinf(z): 649 raise OverflowError 650 return z
17 def round_up(x, base=1): 18 return int(base * round(float(x)/base))
6 def divide(self, dividend, divisor): 7 sign = 1 8 if (dividend < 0 and divisor > 0) or (dividend > 0 and divisor < 0): 9 sign = -1 10 dd, ds = abs(dividend), abs(divisor) 11 if dd < ds: 12 return 0 13 if dividend == -2 ** 31 and divisor == -1: 14 return 2 ** 31 - 1 15 res = 0 16 while ds <= dd: 17 bs_ds = ds # bit shift operator 18 part = 1 19 while not (bs_ds <= dd and bs_ds + bs_ds > dd): 20 bs_ds += bs_ds 21 part += part 22 dd -= bs_ds 23 res += part 24 return res * sign
23 @divide.variant('round') 24 def divide(self, y): 25 return round(self.divide(y))
126 @define_built_in('/') 127 def divide(arguments): 128 # TODO: support exact fractions 129 # TODO: return integer if all arguments were integers and result is whole number 130 check_argument_number('/', arguments, 1) 131 132 if len(arguments) == 1: 133 return FloatingPoint(1 / arguments[0].value) 134 else: 135 result = FloatingPoint(arguments[0].value) 136 137 for argument in arguments.tail: 138 result.value /= argument.value 139 140 return result
55 @pytest.mark.parametrize('x,y,expected', DivisionData.ROUND_VALS) 56 def test_round(x, y, expected): 57 dv = DivisionVariants(x) 58 assert dv.divide.round(y) == expected
4 def roundInt(a): return int(a+0.5)
212 def round(*args): 213 return ast.Round(*args)