@Test public void testFunction2() throws Exception { JsclMathEngine mathEngine = JsclMathEngine.getInstance(); final CustomFunction.Builder jBuilder = new CustomFunction.Builder("f", asList("x", "y"), "z1/z2*√(x^2+y^2)"); mathEngine.getFunctionsRegistry().addOrUpdate(jBuilder.create()); final CustomFunction.Builder jBuilder1 = new CustomFunction.Builder("f2", asList("x", "y"), "√(x^2+y^2)"); mathEngine.getFunctionsRegistry().addOrUpdate(jBuilder1.create()); final CustomFunction.Builder jBuilder2 = new CustomFunction.Builder("f3", asList("x", "y"), "x^2+y^2"); mathEngine.getFunctionsRegistry().addOrUpdate(jBuilder2.create()); try { assertEquals("1", Expression.valueOf("f(1, 1)").numeric().toString()); Assert.fail(); } catch (ArithmeticException e) { } assertEquals("1.414213562373095", Expression.valueOf("f2(1, 1)").numeric().toString()); assertEquals("5", Expression.valueOf("f2(4, 3)").numeric().toString()); assertEquals("2*z1", Expression.valueOf("∂(f3(z1, z2), z1)").expand().toString()); assertEquals("2*z2", Expression.valueOf("∂(f3(z1, z2), z2)").expand().toString()); final CustomFunction.Builder jBuilder3 = new CustomFunction.Builder("f4", asList("x", "y"), "2 000*x^2+y^2"); mathEngine.getFunctionsRegistry().addOrUpdate(jBuilder3.create()); final CustomFunction.Builder jBuilder4 = new CustomFunction.Builder("f5", asList("x", "y"), "2'000* x ^2+y^2\r"); mathEngine.getFunctionsRegistry().addOrUpdate(jBuilder4.create()); }
@Override public Generic numeric() { return selfExpand().numeric(); }
CustomFunction extends Function implements IFunction { @Override public Generic numeric() { return selfExpand().numeric(); } }
CustomFunction extends Function implements IFunction { @Override public Generic numeric() { return selfExpand().numeric(); } private  CustomFunction(@Nonnull String name,
                           @Nonnull List<String> parameterNames,
                           @Nonnull Expression content,
                           @Nullable String description); private  CustomFunction(@Nonnull String name,
                           @Nonnull List<String> parameterNames,
                           @Nonnull String content,
                           @Nullable String description); }
CustomFunction extends Function implements IFunction { @Override public Generic numeric() { return selfExpand().numeric(); } private  CustomFunction(@Nonnull String name,
                           @Nonnull List<String> parameterNames,
                           @Nonnull Expression content,
                           @Nullable String description); private  CustomFunction(@Nonnull String name,
                           @Nonnull List<String> parameterNames,
                           @Nonnull String content,
                           @Nullable String description); @Override int getMinParameters(); @Override int getMaxParameters(); @Override Generic substitute(@Nonnull Variable variable, @Nonnull Generic generic); @Override Generic numeric(); @Override Generic expand(); @Override Generic elementary(); @Override Generic factorize(); @Override Generic selfExpand(); @Override void copy(@Nonnull MathEntity mathEntity); @Override Generic selfElementary(); @Override Generic selfSimplify(); @Override Generic selfNumeric(); @Override Generic antiDerivative(@Nonnull Variable variable); @Override Generic antiDerivative(int n); @Nonnull @Override Generic derivative(@Nonnull Variable variable); @Override Generic derivative(int n); @Nonnull String getContent(); @Nullable String getDescription(); @Nonnull List<String> getParameterNames(); @Nonnull @Override CustomFunction newInstance(); }
CustomFunction extends Function implements IFunction { @Override public Generic numeric() { return selfExpand().numeric(); } private  CustomFunction(@Nonnull String name,
                           @Nonnull List<String> parameterNames,
                           @Nonnull Expression content,
                           @Nullable String description); private  CustomFunction(@Nonnull String name,
                           @Nonnull List<String> parameterNames,
                           @Nonnull String content,
                           @Nullable String description); @Override int getMinParameters(); @Override int getMaxParameters(); @Override Generic substitute(@Nonnull Variable variable, @Nonnull Generic generic); @Override Generic numeric(); @Override Generic expand(); @Override Generic elementary(); @Override Generic factorize(); @Override Generic selfExpand(); @Override void copy(@Nonnull MathEntity mathEntity); @Override Generic selfElementary(); @Override Generic selfSimplify(); @Override Generic selfNumeric(); @Override Generic antiDerivative(@Nonnull Variable variable); @Override Generic antiDerivative(int n); @Nonnull @Override Generic derivative(@Nonnull Variable variable); @Override Generic derivative(int n); @Nonnull String getContent(); @Nullable String getDescription(); @Nonnull List<String> getParameterNames(); @Nonnull @Override CustomFunction newInstance();  }