Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

incorrect square function #188

Closed
nschaeff opened this issue Feb 7, 2024 · 5 comments
Closed

incorrect square function #188

nschaeff opened this issue Feb 7, 2024 · 5 comments

Comments

@nschaeff
Copy link

nschaeff commented Feb 7, 2024

As far as I understand, the square_dd_dd function returns a pair of values that may overlap:
For instance if zlo is zero, 2*alo overlaps with ahi.
A call to Fast2Sum is needed at the end to ensure "normalization".

@inline function square_dd_dd(a::Tuple{T,T}) where {T<:IEEEFloat}

@nschaeff
Copy link
Author

nschaeff commented Feb 7, 2024

Also, in this function, I think (not 100% sure though) that one could ommit zlo = fma(alo, alo, zlo) as alo*alo is always non-significant compared to 2*alo*ahi added just after.

@JeffreySarnoff
Copy link
Member

@nschaeff Thank you for the considered comments.
I have just tested this, with and without LO(x) being zero, over random ranges 0.0:{1e-115, 1e-15, 1e-5, 1e18}, running the tests 90_000_000 times with and without LO(x) being zero. No results required renormalization.
This is not the last word -- as that should be provable.

@nschaeff
Copy link
Author

nschaeff commented Feb 9, 2024

Strange, I just tried a few numbers and all of them required renormalization. For instance:
hi=1.0 and lo = 1.11e-16

@JeffreySarnoff
Copy link
Member

still ..

using DoubleFloats
hi=1.0
lo=1.11e-16
DoubleFloats.two_sum(hi, lo) == (hi, lo) # true
a = Double64(hi, lo)
HILO(a) == (hi, lo) # true
aa = a * a
asqr = square(a)
aa == asqr # true
HILO(asqr) # (1.0000000000000002, -4.4604925031299906e-20) 
DoubleFloats.two_sum(HILO(asqr)...) == HILO(asqr) # true, result is renormalized

@nschaeff
Copy link
Author

nschaeff commented Feb 9, 2024

The fact that you have the HI result not equal to one, means there has been some renormalization, but it is not inside the square fucntion (as you can see, it returns zhi = ahi*ahi = 1 in this case).
It probably happens when you construct the Double64 value in the function square_db_db that calls square_dd_dd.
My mistake, sorry for the false alarm !

@nschaeff nschaeff closed this as completed Feb 9, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants