Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add tests for math lib #530

Merged
merged 9 commits into from
Jan 14, 2020
Merged

Conversation

statementreply
Copy link
Contributor

No description provided.

@antfu
Copy link
Member

antfu commented Jan 12, 2020

Looks awesome!👍 Please keep it up!

@statementreply
Copy link
Contributor Author

I've added tests for math lib APIs except the following:

  • : The existing implementation doesn't work for large powers and will not pass tests.
  • 浮點移位
  • 析浮點數
  • 取底除
  • 取整除

勾股求角 test failures will be resolved by #538.

@statementreply statementreply marked this pull request as ready for review January 14, 2020 16:29
Limitation of the current implementation:

If the expected value is 1 or -1, the test doesn't reject results
greater than 1 or less than -1 respectively.
In a computing environment where +0 and -0 are different, it's expected
that atan2(+0, -x) = +pi, atan2(-0, -x) = -pi. In a computing
environment where there's only one unsigned zero, it's expected that
atan2(0, -x) = +pi.

JavaScript (and the majority if not all of runtime environments wenyan
currently run in) has signed zeros, but currently there's no portable
way to differentiate +0 and -0 in wenyan. As a result, the math library
currently is not able to place +0 and -0 on different branches for
functions like atan2.

This commit modifies the test for atan2 so that it accepts both
atan2(-0, -x) = -pi and atan2(-0, -x) = pi.
@antfu
Copy link
Member

antfu commented Jan 14, 2020

Just for curious. How you do get those test cases? 😲

@statementreply
Copy link
Contributor Author

Just for curious. How you do get those test cases? 😲

  • edge cases: asin(1), sqrt(0)
  • special cases: log(0), atan(Infinity)
  • tricky cases: sin(Math.PI) (shouldn't return zero!), round(0.5 - Number.EPSILON * 0.25) (Java <=6 got it wrong)
  • random cases

@LingDong-
Copy link
Member

Thanks so much for the tests!

@LingDong- LingDong- merged commit c073c03 into wenyan-lang:master Jan 14, 2020
@antfu antfu mentioned this pull request Jan 17, 2020
LingDong- added a commit that referenced this pull request Jan 20, 2020
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.

3 participants