Add floor() and ceil() (#1315)
* add floor() and ceil() functions to simplexpr, akin to round() * document addition of floor() and ceil() * remove unnecessary second argument for floor() and ceil() * Update documentation --------- Co-authored-by: Martin Bogdanov <github () martinbogdanov.com>
This commit is contained in:
parent
eb59d155a2
commit
2c6523a372
4 changed files with 18 additions and 1 deletions
|
@ -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)
|
||||
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -329,6 +329,20 @@ fn call_expr_function(name: &str, args: Vec<DynVal>) -> Result<DynVal, EvalError
|
|||
}
|
||||
_ => 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()?;
|
||||
|
|
|
@ -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`
|
||||
|
|
Loading…
Add table
Reference in a new issue