@Nonnull @Override public String getName() { return this.constant.getName(); }
@Override @Nonnull public String toJava() { if (javaString != null) { return javaString; } else if (value != null) { return String.valueOf(value); } else { return constant.getName(); } }
@Override protected String getSubstituteFromJscl(@Nonnull String match) { return Constants.INF_2.getName().equals(match) ? MathType.INFINITY : super.getSubstituteFromJscl(match); } },
public NumericWrapper(@Nonnull Constant constant) { final IConstant constantFromRegistry = JsclMathEngine.getInstance().getConstantsRegistry().get(constant.getName()); if (constantFromRegistry != null) { if (constantFromRegistry.getName().equals(Constants.I.getName())) { content = Complex.I; } else { if (constantFromRegistry.getValue() != null) { final Double value = constantFromRegistry.getDoubleValue(); if (value == null) { throw new ArithmeticException("Constant " + constant.getName() + " has invalid definition: " + constantFromRegistry.getValue()); } else { content = Real.valueOf(value); } } else { throw new ArithmeticException("Could not create numeric wrapper: constant in registry doesn't have specified value: " + constant.getName()); } } } else { throw new ArithmeticException("Could not create numeric wrapper: constant is not registered in constants registry: " + constant.getName()); } }
@Override public boolean apply(@Nullable IConstant constant) { if (constant != null) { if (localValue.equals(constant.getDoubleValue())) { if (!constant.getName().equals(Constants.PI_INV.getName())) { if (!constant.getName().equals(Constants.PI.getName()) || JsclMathEngine.getInstance().getAngleUnits() == AngleUnit.rad) { return true; } } } } return false; } });
public XyFunction(@Nonnull Generic expression, @Nullable Constant xVariable, @Nullable Constant yVariable, boolean imag) { this.expression = expression; this.xVariable = xVariable; this.yVariable = yVariable; this.imag = imag; if (imag) { this.expressionString = "Im(" + expression.toString() + ")"; this.evaluator = new ImaginaryEvaluator(this); } else { this.expressionString = expression.toString(); this.evaluator = new RealEvaluator(this); } this.xVariableName = xVariable == null ? null : xVariable.getName(); this.yVariableName = yVariable == null ? null : yVariable.getName(); this.arity = 2; if (this.yVariableName == null) { this.arity--; } if (this.xVariableName == null) { this.arity--; } this.id = this.expressionString + "_" + Strings.getNotEmpty(this.xVariableName, "") + "_" + Strings.getNotEmpty(this.yVariableName, ""); }
public String toJava() { final IConstant constantFromRegistry = JsclMathEngine.getInstance().getConstantsRegistry().get(getName()); if (constantFromRegistry != null) { return constantFromRegistry.toJava(); } final StringBuilder result = new StringBuilder(); result.append(name); if (prime != 0) { if (prime <= PRIME_CHARS) result.append(underscores(prime)); else result.append("_").append(prime); } for (Generic subscript : subscripts) { result.append("[").append(subscript.integerValue().intValue()).append("]"); } return result.toString(); }
@Nonnull public static Set<Constant> getNotSystemConstants(@Nonnull Generic expression) { final Set<Constant> notSystemConstants = new HashSet<Constant>(); for (Constant constant : expression.getConstants()) { IConstant var = Locator.getInstance().getEngine().getVarsRegistry().get(constant.getName()); if (var != null && !var.isSystem() && !var.isDefined()) { notSystemConstants.add(constant); } } return notSystemConstants; }
@Override public String toString() { final Generic parameter = parameters[0]; if (parameter != null) { try { if (JsclInteger.ONE.negate().equals(parameter.integerValue())) { return Constants.I.getName(); } else { return super.toString(); } } catch (NotIntegerException e) { return super.toString(); } } else { return super.toString(); } }