[calculation/additional_outputs] Use input rather than output if possible, and open on tan

This commit is contained in:
Joachim LF
2022-06-17 13:09:45 +02:00
parent 0751c88a2d
commit 25cd0d44f3
5 changed files with 15 additions and 11 deletions

View File

@@ -251,8 +251,11 @@ Calculation::AdditionalInformationType Calculation::additionalInformationType(Co
* - > input: 2cos(2) - cos(2)
* > output: cos(2)
*/
if (input().isDefinedCosineOrSine(context, complexFormat, preferences->angleUnit()) || o.isDefinedCosineOrSine(context, complexFormat, preferences->angleUnit())) {
return AdditionalInformationType::Trigonometry;
if (i.isDefinedCosineOrSineOrTangent(context, complexFormat, preferences->angleUnit())) {
return AdditionalInformationType::TrigonometryInput;
}
if (o.isDefinedCosineOrSineOrTangent(context, complexFormat, preferences->angleUnit())) {
return AdditionalInformationType::TrigonometryOutput;
}
if (o.hasUnit()) {
Expression unit;

View File

@@ -40,7 +40,8 @@ public:
Integer,
Rational,
SecondDegree,
Trigonometry,
TrigonometryInput,
TrigonometryOutput,
Unit,
Matrix,
Complex

View File

@@ -103,12 +103,12 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
vc = &m_complexController;
} else if (additionalInfoType == Calculation::AdditionalInformationType::SecondDegree) {
vc = &m_secondDegreeController;
} else if (additionalInfoType == Calculation::AdditionalInformationType::Trigonometry) {
} else if (additionalInfoType == Calculation::AdditionalInformationType::TrigonometryInput) {
vc = &m_trigonometryController;
// Find which of the input or output is the cosine/sine
ExpressionNode::Type t = e.type();
e = t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine ? e : calculationAtIndex(focusRow)->input();
} else if (additionalInfoType == Calculation::AdditionalInformationType::Integer) {
e = calculationAtIndex(focusRow)->input();
} else if (additionalInfoType == Calculation::AdditionalInformationType::TrigonometryOutput) {
vc = &m_trigonometryController;
} else if (additionalInfoType == Calculation::AdditionalInformationType::Integer) {
vc = &m_integerController;
} else if (additionalInfoType == Calculation::AdditionalInformationType::Rational) {
vc = &m_rationalController;

View File

@@ -159,7 +159,7 @@ public:
bool isRationalOne() const;
bool isRandom() const { return node()->isRandom(); }
bool isParameteredExpression() const { return node()->isParameteredExpression(); }
bool isDefinedCosineOrSine(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
bool isDefinedCosineOrSineOrTangent(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
bool isBasedIntegerCappedBy(const char * integerString) const;
bool isDivisionOfIntegers() const;
bool hasDefinedComplexApproximation(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;

View File

@@ -260,9 +260,9 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex
return !isMultivariablePolynomial;
}
bool Expression::isDefinedCosineOrSine(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
bool Expression::isDefinedCosineOrSineOrTangent(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
ExpressionNode::Type t = type();
if (t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine) {
if (t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine || t == ExpressionNode::Type::Tangent) {
float r = childAtIndex(0).approximateToScalar<float>(context, complexFormat, angleUnit);
if (!std::isnan(r)) {
return true;