From 2bb1730373892d8dbcbbbde2cbc98943ab321a19 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 28 Apr 2019 14:43:51 +0100 Subject: [PATCH] little trick when it comes to if else and a return statement: remove the else and reduce the indentation a bit --- src/add/fsqrt.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/add/fsqrt.py b/src/add/fsqrt.py index 60aa7e02..cb6a8ac0 100644 --- a/src/add/fsqrt.py +++ b/src/add/fsqrt.py @@ -48,9 +48,8 @@ def main(mantissa, exponent): if exponent & 1 != 0: return sqrt(mantissa << 1), # shift mantissa up ((exponent - 1) / 2) # subtract 1 from exp to compensate - else: - return sqrt(mantissa), # mantissa as-is - (exponent / 2) # no compensating needed on exp + return sqrt(mantissa), # mantissa as-is + (exponent / 2) # no compensating needed on exp for Q in range(1, int(1e7)): print(Q, sqrt(Q), sqrtsimple(Q), int(Q**0.5)) -- 2.30.2