Log In  

> print(sqrt(3))
1.75
> print(sqrt(3)^2)
3.063
> print(1.732^2)
3

or, with the same level of precision

> print(1.73^2)
2.993

P#11834 2015-07-25 19:10 ( Edited 2015-07-26 04:23)

If anyone else has this problem, I am currently doing all right with this (which also works around the other sqrt bug):

sqrt0 = sqrt
function sqrt(x)
    if (x<=0) return 0
    if (x>=32761) return 181.0
    local s = 1
    while x <= 100 do
        x *= 100
        s *= 10
    end
    return sqrt0(x)/s
end

I haven't done much work to find the optimal domain, and arguably powers of 2 would be better than powers of 10, but this seems to work okay for my needs.

P#11837 2015-07-26 00:23 ( Edited 2015-07-26 04:23)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-16 18:39:22 | 0.005s | Q:11