Expand description
What a slider’s typed entry accepts: a number or a simple expression, written as the user’s locale writes numbers, with an optional unit after it.
- Numbers take a point or a comma as the decimal separator; when a
text has both, the last one is the decimal separator and the other
groups thousands (
1,234.5,1.234,5). Spaces, no-break spaces and apostrophes before three digits group thousands (1 234,5,1’234.5). - Operators:
+ - * /,^(power, right-associative), parentheses, a sign before any term.xis the slider’s current value. - What follows the expression is a unit and is ignored (
1.5 EV,+3%); a text that starts with neither a number, a sign,xnor a parenthesis is not a value.
use egui_pop_core::slider::expr::eval;
assert_eq!(eval("1,5 EV", 0.0), Some(1.5));
assert_eq!(eval("x * 2", 0.25), Some(0.5));
assert_eq!(eval("(1 + 2) ^ 2 - 1", 0.0), Some(8.0));
assert_eq!(eval("1 234,5", 0.0), Some(1234.5));
assert_eq!(eval("EV", 0.0), None);
assert_eq!(eval("1/0", 0.0), None);Functions§
- eval
- The value of
text,xbeingcurrent;Nonewhen it is not a value or not finite.