Add log10 for Decimal.
This commit is contained in:
parent
06f217d526
commit
288d575046
@ -14,6 +14,8 @@ Enhancements
|
|||||||
* Added a number of constants to `Dynamic`.
|
* Added a number of constants to `Dynamic`.
|
||||||
* Added a number of constants and `fromXXX` constant methods to `Dynamic`.
|
* Added a number of constants and `fromXXX` constant methods to `Dynamic`.
|
||||||
* `parse_float()`, `PI()` and `E()` now defer to `Decimal` under `no_float` if `decimal` is turned on.
|
* `parse_float()`, `PI()` and `E()` now defer to `Decimal` under `no_float` if `decimal` is turned on.
|
||||||
|
* Added `log10()` for `Decimal`.
|
||||||
|
* `ln` for `Decimal` is now checked and won't panic.
|
||||||
|
|
||||||
|
|
||||||
Version 1.0.2
|
Version 1.0.2
|
||||||
|
@ -92,7 +92,7 @@ default-features = false
|
|||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.rust_decimal]
|
[dependencies.rust_decimal]
|
||||||
version = "1.14.2"
|
version = "1.15"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["maths"]
|
features = ["maths"]
|
||||||
optional = true
|
optional = true
|
||||||
|
@ -339,8 +339,23 @@ mod decimal_functions {
|
|||||||
Ok(x.exp())
|
Ok(x.exp())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn ln(x: Decimal) -> Decimal {
|
#[rhai_fn(return_raw)]
|
||||||
x.ln()
|
pub fn ln(x: Decimal) -> Result<Decimal, Box<EvalAltResult>> {
|
||||||
|
if cfg!(not(feature = "unchecked")) {
|
||||||
|
x.checked_ln()
|
||||||
|
.ok_or_else(|| make_err(format!("Error taking the natural log of {}", x)))
|
||||||
|
} else {
|
||||||
|
Ok(x.ln())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[rhai_fn(name = "log", return_raw)]
|
||||||
|
pub fn log10(x: Decimal) -> Result<Decimal, Box<EvalAltResult>> {
|
||||||
|
if cfg!(not(feature = "unchecked")) {
|
||||||
|
x.checked_log10()
|
||||||
|
.ok_or_else(|| make_err(format!("Error taking the log of {}", x)))
|
||||||
|
} else {
|
||||||
|
Ok(x.log10())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[rhai_fn(name = "floor", get = "floor")]
|
#[rhai_fn(name = "floor", get = "floor")]
|
||||||
pub fn floor(x: Decimal) -> Decimal {
|
pub fn floor(x: Decimal) -> Decimal {
|
||||||
|
Loading…
Reference in New Issue
Block a user