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

sin for complex numbers doesn't have extremely high precision, it's less accurate than that of real numbers #2523

Closed
yifanwww opened this issue Apr 11, 2022 · 1 comment · Fixed by #2525

Comments

@yifanwww
Copy link
Contributor

yifanwww commented Apr 11, 2022

When I was implementing the logarithm of gamma function for complex numbers, I found that the lgamma for complex numbers is not quite as precies as lgamma for reals.

Finally I found out that, the precision of sin for complex numbers is high, but not extremely high.

console.log(math.complex(3.141592653589793e-9, 3.14159273913291e-9).sin())

// outputs: { re: 3.141592653589793e-9, im: 3.1415927637112873e-9 }

We can get a reference result from WolframAlpha: https://www.wolframalpha.com/input?i=sin%5B3.141592653589793e-9+%2B+3.14159273913291e-9i%5D

3.141592653589793010335426404376673215359558342768379304724... × 10^-9 +
3.141592739132909989664574439900073779337556883790059589676... × 10^-9 i

The real numbers are the same, but there is a little difference between the imaginary numbers:

3.141592653589793e-9
3.141592653589793010335426404376673215359558342768379304724... × 10^-9

3.1415927637112873e-9
3.141592739132909989664574439900073779337556883790059589676... × 10^-9
         ^

I'm not sure how much impact this difference has. Even I use the correct sin results to continue to compute lgamma, the precision get improved, but it seems that it's still not as precies as that for reals.

But anyway, this issue is for the sine algorithm for complex numbers.

@gwhitney
Copy link
Collaborator

As you can see, this was a bug reported in complex.js almost four years ago, with a suggested fix that seems to work absolutely fine. Hopefully this additional report can induce some motion on a fix; if not, we will simply implement the fix suggested in the above issue in complex.js, but internally in mathjs. Thanks for the detailed report!

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 a pull request may close this issue.

2 participants