Proyecto

General

Perfil

Warnings » Histórico » Versión 1

Federico Vera, 2018-06-10 00:03

1 1 Federico Vera
# Warnings
2
3
# Checking for errors
4
# Variable naming
5
Avoid variables and functions with the same name as build-in functions, constant or operators (or even custom functions). Even though this is possible and permitted by this version of `exp4j` we intent to create a more strict version in the future. 
6
7
Why is this bad? well... if we have a built-in function called `sin(x)` and create a second function called `sin(x, y)` and use a variable called `sin` you might end up with expressions like: `sin(sin(sin, sin(sin)) + sin) ` this may sound dumb, but unfortunately is very common.
8
9
# Performance
10
11
## Multiple calls to `Expression#evaluate()`
12
This is a common mistake, values returned from `Expression#evaluate()` are not cached, so every call will reevaluate the entire expression. There are two options:
13
1. Save the value of `Expression#evaluate()` instead of calling it multiple times
14
1. Implement the result cache! Checkout [#15](https://gitlab.com/riddler_arg/exp4j/issues/15) for some details
15
16
## Simplifier enabled for single evaluation
17
18
The simplifier needs to do a full evaluation of the code in order to make the simplifications, so it should not be enabled for single evaluation, since this will create a 100% loss in performance (the expression needs to be evaluated twice).
19
## Write simplifiable expressions
20
21
Even though you can use the `Expression#toString()` method to checkout the number of tokens, the rule of thumb is to sort the expression:
22
23
For instance the expression `2 + 3x - 1` is not simplifiable, because the `Simplifier` does not alter the order of the operators (Operators can be overridden and there's no way of handling those scenarios).
24
If you change `2 + 3x - 1` to `2 - 1 + 3x` it will be simplified to `1 + 3x`.
Volver al inicio