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

Fix trigonometric function's output when input is inf #1352

Merged
merged 4 commits into from
Dec 24, 2024

Conversation

Kaida-Amethyst
Copy link
Contributor

There are some problems:

sin(inf) should be NaN, not Infinity
sin(-inf) should be NaN, not -Infinity
cos(inf) should be NaN, not Infinity
cos(-inf) should be NaN, not -Infinity
tan(inf) should be NaN, not Infinity
tan(-inf) should be NaN, not -Infinity
asin(inf) should be NaN, not Infinity
asin(-inf) should be NaN, not -Infinity
acos(inf) should be NaN, not Infinity
acos(-inf) should be NaN, not -Infinity

Verify it in python (Not only python, I get same resutlt in C, rust, and the like):

>>> import numpy as np
>>> import warnings
>>> warnings.simplefilter("ignore") # ignore warnings because numpy will throw warnings when output contains `nan`
>>> numbers_contain_inf = np.array([-np.inf, np.inf, 0.0, 1.0])
>>> np.sin(numbers_contain_inf)
array([       nan,        nan, 0.        , 0.84147098])
>>> np.cos(numbers_contain_inf)
array([       nan,        nan, 1.        , 0.54030231])
>>> np.tan(numbers_contain_inf)
array([       nan,        nan, 0.        , 1.55740772])
>>> np.arcsin(numbers_contain_inf)
array([       nan,        nan, 0.        , 1.57079633])
>>> np.arccos(numbers_contain_inf)
array([       nan,        nan, 1.57079633, 0.        ])
>>> 

@coveralls
Copy link
Collaborator

coveralls commented Dec 23, 2024

Pull Request Test Coverage Report for Build 4301

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • 38 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.7%) to 80.587%

Files with Coverage Reduction New Missed Lines %
option/option.mbt 38 24.53%
Totals Coverage Status
Change from base Build 4300: -0.7%
Covered Lines: 4587
Relevant Lines: 5692

💛 - Coveralls

@bobzhang bobzhang enabled auto-merge (rebase) December 24, 2024 02:28
@bobzhang bobzhang merged commit 9cb4c07 into moonbitlang:main Dec 24, 2024
13 checks passed
@Kaida-Amethyst Kaida-Amethyst deleted the trig-func-special-input branch December 24, 2024 07:44
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.

4 participants