(MathParser parser, String variable, String exp)
| 195 | } |
| 196 | |
| 197 | public static double limit(MathParser parser, String variable, String exp) throws MathParserException { |
| 198 | MathParser newParser = parser.clone(); |
| 199 | variable = variable.replace("->", "="); |
| 200 | if (!variable.contains("=")) |
| 201 | throw new MathInvalidParameterException("limit(): invalid variable (" + variable + "), must be something like x->2"); |
| 202 | |
| 203 | String[] var = variable.split("="); |
| 204 | String variableName = var[0]; |
| 205 | if (!Utils.isIdentifier(variableName)) |
| 206 | throw new MathInvalidParameterException("limit(): invalid variable name (" + variableName + ")"); |
| 207 | |
| 208 | double a; |
| 209 | var[1] = Utils.realTrim(var[1]); |
| 210 | if (var[1].equalsIgnoreCase("+inf") || var[1].equalsIgnoreCase("inf")) |
| 211 | a = Double.POSITIVE_INFINITY; |
| 212 | else if (var[1].equalsIgnoreCase("-inf")) |
| 213 | a = Double.NEGATIVE_INFINITY; |
| 214 | else |
| 215 | a = newParser.parse(var[1]); |
| 216 | |
| 217 | //newParser.setRoundEnabled(false); |
| 218 | newParser.addVariable(variableName, 0, 0); |
| 219 | return LimitFunction.limit(newParser, newParser.getVariable(variableName), exp, a); |
| 220 | } |
| 221 | |
| 222 | public static double derivative(MathParser parser, String variableName, String exp, double x) throws MathParserException { |
| 223 | if (!Utils.isIdentifier(variableName)) |
no test coverage detected