jiggzson / nerdamer

a symbolic math expression evaluator for javascript
http://www.nerdamer.com
MIT License
517 stars 82 forks source link

Issue with throwing an undefined error instead of returning infinity. #470

Closed Saikedo closed 4 years ago

Saikedo commented 5 years ago

There are numerous cases where nerdamer throws an error instead of returning infinity. One example is tan(pi/2). So just for tan(pi/2) it is fine to return an error saying it is not defined but we start getting issues with expressions such as 1/(tan(pi/2)). All the other calculators are returning 0 for this value since tan(pi/2) goes to positive infinity.

Is this something that can be easily fixed? Any suggestings on how these situations can be handled?

jiggzson commented 5 years ago

Would doing a try, catch and returning the limit of the function if it's an undefined error work?

Happypig375 commented 5 years ago

Important question: Should Infinity or -Infinity be returned? Different limits from different directions. We can add a UnknownSignInfinity though.

Happypig375 commented 5 years ago

Or ComplexInfinity like Wolfram Alpha.

Saikedo commented 5 years ago

@Happypig375 Can we somehow distinguish between the negative and positive infinities when returning? It would be great if we can indicate the sign of the infinity.

Happypig375 commented 5 years ago

Infinity and -Infinity are both in Nerdamer. However, tan(pi/2) is Infinity when approached from the left hand side, -Infinity from the right hand side. Both answers are incorrect if you consider the other case. ComplexInfinity, which is an infinity with unknown sign, is best as the answer.

jiggzson commented 4 years ago

@Saikedo, what was your approach ultimately with this issue?