Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Fix issue #96: The value of tan((2k+1)π/2)is not correct #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,38 @@ public void onAnimationFinished() {
void setState(CalculatorState state) {
mCurrentState = state;
}

/**
* When input is tan((2k+1)*Pi/2) the result should be Infinity.
* @param result
* The original result of tan function .
* @return
* If the original result is larger than 1, then return Infinity,
* or return original result.
*/
public String executeTAN(String result){
int index = result.indexOf('^');
if(index != -1){
String firstPart = result.substring(0, index + 1);
String secondPart = result.substring(index + 1, result.length());
String exponent = result.substring(index + 1, result.length() - 2);
if(Integer.parseInt(exponent) > 1){
result = "$$Infinity$$";
}
return result;
}
return result;
}

@Override
public void onEvaluated(String expr, String result, int resultId) {
if (resultId == LogicEvaluator.RESULT_OK) {
//Parse user input to get the function to be executed and operand.
String operator = expr.substring(0,3).toLowerCase();
String nums = expr.substring(4, expr.length() - 1);
if(operator.equals("tan")){
result = executeTAN(result);
}
if (mCurrentState == CalculatorState.EVALUATE) {
onResult(result);
saveHistory(expr, result, true);
Expand Down