Skip to content

Conversation

@statementreply
Copy link
Contributor

@statementreply statementreply commented Dec 29, 2019

Robust: 4/4 (Does it work for all input values?)
Accurate: 4/4 (How accurate is the result?)
Well behaved: 4/4 (Does it preserve math properties?)

算經.平方根 should return exactly the same result as Math.sqrt for all input numbers except -0, for which Math.sqrt(-0) = -0 complying to IEEE 754, but 算經.平方根(-0) = +0.

This will also make the current implementation of hypot a tiny bit more accurate than before. I'll rate hypot 4/2/3 after this patch (previously 4/2/2) due to the following property being preserved when sqrt is correctly rounded:

hypot(x, y) >= |x| && hypot(x, y) >= |y|

Robust: 4/4 (Does it work for all input values?)
Accurate: 4/4 (How accurate is the result?)
Well behaved: 4/4 (Does it preserve math properties?)

算經.平方根 should return exactly the same result as Math.sqrt for all
input numbers except -0, for which Math.sqrt(-0) = -0 complying to IEEE
754, but 算經.平方根(-0) = +0.

This will also make the current implementation of hypot a tiny bit more
accurate than before. I'll rate hypot 4/2/3 after this patch (previously
4/2/2) due to the following property being preserved when sqrt is
correctly rounded:

hypot(x, y) >= |x| && hypot(x, y) >= |y|
@LingDong- LingDong- merged commit f5907d4 into wenyan-lang:master Dec 29, 2019
@LingDong-
Copy link
Member

Thanks!

@antfu antfu mentioned this pull request Dec 29, 2019
@statementreply statementreply deleted the accurate-sqrt branch December 31, 2019 14:42
LingDong- added a commit that referenced this pull request Jan 20, 2020
stdlib: Implement correctly rounded sqrt (4/4/4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants