powi/powf simplexpr functions (#1255)

* Add `powi`/`powf` expressions

* Update docs
This commit is contained in:
ovalkonia 2024-12-27 01:29:26 +02:00 committed by GitHub
parent f2b687043e
commit c3b28d8fe5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View file

@ -345,6 +345,22 @@ fn call_expr_function(name: &str, args: Vec<DynVal>) -> Result<DynVal, EvalError
} }
_ => Err(EvalError::WrongArgCount(name.to_string())), _ => Err(EvalError::WrongArgCount(name.to_string())),
}, },
"powi" => match args.as_slice() {
[num, n] => {
let num = num.as_f64()?;
let n = n.as_i32()?;
Ok(DynVal::from(f64::powi(num, n)))
}
_ => Err(EvalError::WrongArgCount(name.to_string())),
},
"powf" => match args.as_slice() {
[num, n] => {
let num = num.as_f64()?;
let n = n.as_f64()?;
Ok(DynVal::from(f64::powf(num, n)))
}
_ => Err(EvalError::WrongArgCount(name.to_string())),
},
"sin" => match args.as_slice() { "sin" => match args.as_slice() {
[num] => { [num] => {
let num = num.as_f64()?; let num = num.as_f64()?;

View file

@ -43,6 +43,7 @@ Supported currently are the following features:
- `round(number, decimal_digits)`: Round a number to the given amount of decimals - `round(number, decimal_digits)`: Round a number to the given amount of decimals
- `sin(number)`, `cos(number)`, `tan(number)`, `cot(number)`: Calculate the trigonometric value of a given number in **radians** - `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 - `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`
- `degtorad(number)`: Converts a number from degrees to radians - `degtorad(number)`: Converts a number from degrees to radians
- `radtodeg(number)`: Converts a number from radians to degrees - `radtodeg(number)`: Converts a number from radians to degrees
- `replace(string, regex, replacement)`: Replace matches of a given regex in a string - `replace(string, regex, replacement)`: Replace matches of a given regex in a string