Add trigonometric functions (#823)
This commit is contained in:
parent
efce800aff
commit
9d0b667dea
3 changed files with 46 additions and 0 deletions
|
@ -17,6 +17,7 @@ All notable changes to eww will be listed here, starting at changes since versio
|
||||||
- Add `jq` function, offering jq-style json processing
|
- Add `jq` function, offering jq-style json processing
|
||||||
- Add `justify` property to the label widget, allowing text justification (By: n3oney)
|
- Add `justify` property to the label widget, allowing text justification (By: n3oney)
|
||||||
- Add `EWW_TIME` magic variable (By: Erenoit)
|
- Add `EWW_TIME` magic variable (By: Erenoit)
|
||||||
|
- Add trigonometric functions (`sin`, `cos`, `tan`, `cot`) and degree/radian conversions (`degtorad`, `radtodeg`) (By: end-4)
|
||||||
|
|
||||||
## [0.4.0] (04.09.2022)
|
## [0.4.0] (04.09.2022)
|
||||||
|
|
||||||
|
|
|
@ -320,6 +320,48 @@ fn call_expr_function(name: &str, args: Vec<DynVal>) -> Result<DynVal, EvalError
|
||||||
}
|
}
|
||||||
_ => Err(EvalError::WrongArgCount(name.to_string())),
|
_ => Err(EvalError::WrongArgCount(name.to_string())),
|
||||||
},
|
},
|
||||||
|
"sin" => match args.as_slice() {
|
||||||
|
[num] => {
|
||||||
|
let num = num.as_f64()?;
|
||||||
|
Ok(DynVal::from(num.sin()))
|
||||||
|
}
|
||||||
|
_ => Err(EvalError::WrongArgCount(name.to_string())),
|
||||||
|
},
|
||||||
|
"cos" => match args.as_slice() {
|
||||||
|
[num] => {
|
||||||
|
let num = num.as_f64()?;
|
||||||
|
Ok(DynVal::from(num.cos()))
|
||||||
|
}
|
||||||
|
_ => Err(EvalError::WrongArgCount(name.to_string())),
|
||||||
|
},
|
||||||
|
"tan" => match args.as_slice() {
|
||||||
|
[num] => {
|
||||||
|
let num = num.as_f64()?;
|
||||||
|
Ok(DynVal::from(num.tan()))
|
||||||
|
}
|
||||||
|
_ => Err(EvalError::WrongArgCount(name.to_string())),
|
||||||
|
},
|
||||||
|
"cot" => match args.as_slice() {
|
||||||
|
[num] => {
|
||||||
|
let num = num.as_f64()?;
|
||||||
|
Ok(DynVal::from(1.0 / num.tan()))
|
||||||
|
}
|
||||||
|
_ => Err(EvalError::WrongArgCount(name.to_string())),
|
||||||
|
},
|
||||||
|
"degtorad" => match args.as_slice() {
|
||||||
|
[num] => {
|
||||||
|
let num = num.as_f64()?;
|
||||||
|
Ok(DynVal::from(num.to_radians()))
|
||||||
|
}
|
||||||
|
_ => Err(EvalError::WrongArgCount(name.to_string())),
|
||||||
|
},
|
||||||
|
"radtodeg" => match args.as_slice() {
|
||||||
|
[num] => {
|
||||||
|
let num = num.as_f64()?;
|
||||||
|
Ok(DynVal::from(num.to_degrees()))
|
||||||
|
}
|
||||||
|
_ => Err(EvalError::WrongArgCount(name.to_string())),
|
||||||
|
},
|
||||||
"matches" => match args.as_slice() {
|
"matches" => match args.as_slice() {
|
||||||
[string, pattern] => {
|
[string, pattern] => {
|
||||||
let string = string.as_string()?;
|
let string = string.as_string()?;
|
||||||
|
|
|
@ -39,6 +39,9 @@ Supported currently are the following features:
|
||||||
- for this, the object/array value needs to refer to a variable that contains a valid json string.
|
- for this, the object/array value needs to refer to a variable that contains a valid json string.
|
||||||
- some function calls:
|
- some function calls:
|
||||||
- `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**
|
||||||
|
- `degtorad(number)`: Converts a number from degrees to radians
|
||||||
|
- `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
|
||||||
- `search(string, regex)`: Search for a given regex in a string (returns array)
|
- `search(string, regex)`: Search for a given regex in a string (returns array)
|
||||||
- `matches(string, regex)`: check if a given string matches a given regex (returns bool)
|
- `matches(string, regex)`: check if a given string matches a given regex (returns bool)
|
||||||
|
|
Loading…
Add table
Reference in a new issue