Skip to content

Commit

Permalink
Fix square root with non-standard fixed-point parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkskeller committed Dec 5, 2023
1 parent 081ad88 commit 3e31341
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Compiler/mpc_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,15 @@ def norm_simplified_SQ(b, k):
#
# @return g: approximated sqrt
def sqrt_simplified_fx(x):
# adapt parameters to fit the algorithm
f = x.f
k = x.k
my_f = max(f, k - f + 1)
shift = my_f - f
my_k = k + shift
assert my_k < 2 * my_f
x = type(x)._new(x.v << shift, f=my_f, k=my_k)

# fix theta (number of iterations)
theta = max(int(math.ceil(math.log(x.k))), 6)

Expand Down Expand Up @@ -670,7 +679,7 @@ def sqrt_simplified_fx(x):
g = H * x
g = g

return g
return type(x)._new((g * 2 ** -shift).v, f=f, k=k)


##
Expand Down

0 comments on commit 3e31341

Please sign in to comment.