Skip to content

# Square Roots Mathlib.sma

Forums Forums SIMPOL Programming Square Roots Mathlib.sma

Tagged:

Viewing 4 posts - 1 through 4 (of 4 total)
• Author
Posts
• #3504
JD Kromkowski
Participant

There is a problem with square roots in mathlib.sma The conversion to string in binary in estimateroot function will give a string too long error

Try taking square root of 45.053164859997081458307!

Below is a possible fix. Newton’s method. The first estimate is estimate on integer part of n, using what was already written.

// n = number for which to find squareroot
// est = first estimate using what was written already on the integer part of n
// i = int(n)
// est = sqrt(i,2)

number n, est, num, denom, sub, sqroot, fixed
integer i, precount
// 45.053164859997081458307
n = 45053164859997081458307/1000000000000000000000
i = int(n)
precount = 0
est = sqrt(i,2)

while fixed <> .fix(est,100000000000000)
fixed = .fix(est,100000000000000)
num = raisetopower(est,2) – n
denom = 2*est
sub = (num/denom)
sqroot = est – sub
est = sqroot
precount = precount + 1
end while

#3507
Michael
Keymaster

Thanks for the report. A new sqrt() implementation is part of the release.

#3532
JD Kromkowski
Participant

I see you went with brute force. Works! Thanks.

#3533
Michael
Keymaster

Good, glad to hear it.

Viewing 4 posts - 1 through 4 (of 4 total)
• You must be logged in to reply to this topic.