For the author's information: Starting with Factorio 2.0, the formula supports the following functions:
abs(value): Returns absolute value of the given argument; i.e. if the argument is negative, it is inverted.
log2(value): Returns a binary logarithm of the given value.
sign(value): Returns -1 for negative numbers, 0 for zero (regardless of sign), 1 for positive numbers
max(value1, value2, ...): Returns the greater of the given values. Supports between 2 and 255 arguments.
min(value1, value2, ...): Returns the smaller of the given values. Supports between 2 and 255 arguments.
I think the "max" and "min" here would be very useful to avoid extreme values.
Check out https://lua-api.factorio.com/latest/types/MathExpression.html for details. Also note that starting with 2.0, the formula also supports hexadecimal numbers (0xFF) and scientific notation ("1e3"), so full 2.0 support would require being able to parse these numbers.