diff --git a/CHANGELOG.md b/CHANGELOG.md index e20c84a..6fe1a61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add `log` function calls to simplexpr (By: topongo) - Add `:lines` and `:wrap-mode` properties to label widget (By: vaporii) - Add `value-pos` to scale widget (By: ipsvn) +- Add `floor` and `ceil` function calls to simplexpr (By: wsbankenstein) ## [0.6.0] (21.04.2024) diff --git a/Cargo.lock b/Cargo.lock index 7c03984..dbe73fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" diff --git a/crates/simplexpr/src/eval.rs b/crates/simplexpr/src/eval.rs index 8ee0d84..fc56c85 100644 --- a/crates/simplexpr/src/eval.rs +++ b/crates/simplexpr/src/eval.rs @@ -329,6 +329,20 @@ fn call_expr_function(name: &str, args: Vec) -> Result Err(EvalError::WrongArgCount(name.to_string())), }, + "floor" => match args.as_slice() { + [num] => { + let num = num.as_f64()?; + Ok(DynVal::from(num.floor())) + } + _ => Err(EvalError::WrongArgCount(name.to_string())), + }, + "ceil" => match args.as_slice() { + [num] => { + let num = num.as_f64()?; + Ok(DynVal::from(num.ceil())) + } + _ => Err(EvalError::WrongArgCount(name.to_string())), + }, "min" => match args.as_slice() { [a, b] => { let a = a.as_f64()?; diff --git a/docs/src/expression_language.md b/docs/src/expression_language.md index 106776a..f9c0757 100644 --- a/docs/src/expression_language.md +++ b/docs/src/expression_language.md @@ -41,6 +41,8 @@ Supported currently are the following features: - for this, the object/array value needs to refer to a variable that contains a valid json string. - some function calls: - `round(number, decimal_digits)`: Round a number to the given amount of decimals + - `floor(number)`: Round a number up to the nearest integer + - `ceil(number)`: Round a number down to the nearest integer - `sin(number)`, `cos(number)`, `tan(number)`, `cot(number)`: Calculate the trigonometric value of a given number in **radians** - `min(a, b)`, `max(a, b)`: Get the smaller or bigger number out of two given numbers - `powi(num, n)`, `powf(num, n)`: Raise number `num` to power `n`. `powi` expects `n` to be of type `i32`