From 098ad75c5ccee80ff7156d9183cb78db378ba821 Mon Sep 17 00:00:00 2001 From: Khalid Date: Sun, 3 Mar 2024 20:40:38 +0500 Subject: [PATCH] Minor code improvements div_ceil function improved, now it's intuitive. pi_as_string now raising error when number of digits is negative. --- src/starkware/crypto/signature/math_utils.py | 2 ++ src/starkware/python/math_utils.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/starkware/crypto/signature/math_utils.py b/src/starkware/crypto/signature/math_utils.py index 2dc3a4d4..bf550fe9 100644 --- a/src/starkware/crypto/signature/math_utils.py +++ b/src/starkware/crypto/signature/math_utils.py @@ -29,6 +29,8 @@ def pi_as_string(digits: int) -> str: """ Returns pi as a string of decimal digits without the decimal point ("314..."). """ + if digits < 0: + raise ValueError("Negative number of digits") mpmath.mp.dps = digits # Set number of digits. return "3" + str(mpmath.mp.pi)[2:] diff --git a/src/starkware/python/math_utils.py b/src/starkware/python/math_utils.py index b676f85b..5181c697 100644 --- a/src/starkware/python/math_utils.py +++ b/src/starkware/python/math_utils.py @@ -19,8 +19,9 @@ def safe_div(x: int, y: int): def div_ceil(x, y): - assert isinstance(x, int) and isinstance(y, int) - return -((-x) // y) + if not isinstance(x, int) or not isinstance(y, int): + raise TypeError("Arguments must be integers.") + return (x + y - 1) // y def div_mod(n, m, p):