MCPcopy Index your code
hub / github.com/Aghajari/MathParser / IF

Method IF

MathParser/src/com/aghajari/math/Functions.java:326–364  ·  view source on GitHub ↗
(MathParser parser, String condition, String a, String b)

Source from the content-addressed store, hash-verified

324 }
325
326 public static double IF(MathParser parser, String condition, String a, String b) throws MathParserException {
327 condition = Utils.realTrim(condition);
328 Matcher matcher = Utils.splitIf.matcher(condition);
329 double ca, cb = 0;
330 String type = "!=";
331
332 if (matcher.find()) {
333 ca = parser.parse(matcher.group(1).trim());
334 cb = parser.parse(matcher.group(3).trim());
335 type = matcher.group(2).trim();
336 } else
337 ca = parser.parse(condition);
338
339 boolean c;
340 switch (type) {
341 case "==":
342 case "=":
343 c = ca == cb;
344 break;
345 case ">=":
346 c = ca >= cb;
347 break;
348 case "<=":
349 c = ca <= cb;
350 break;
351 case ">":
352 c = ca > cb;
353 break;
354 case "<":
355 c = ca < cb;
356 break;
357 case "<>":
358 case "!=":
359 default:
360 c = ca != cb;
361 break;
362 }
363 return parser.parse(c ? a : b);
364 }
365
366
367 public static double cot(double x) {

Callers

nothing calls this directly

Calls 3

realTrimMethod · 0.95
trimMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected