Every line of 'python math round' 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.
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