summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
authorEric Biedert <github@ericbiedert.de>2023-04-11 14:13:01 +0200
committerGitHub <noreply@github.com>2023-04-11 14:13:01 +0200
commitc7db709da53e0559adabc99d483a374224ef5ce8 (patch)
tree22ab5ce508bb1ba6aafd9b2c61066069b9e771ab /library/src
parentef50f1b011af61d7f145fcbb25e90fb002d5f785 (diff)
Allow treating ratios as floats (#681)
Diffstat (limited to 'library/src')
-rw-r--r--library/src/compute/construct.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/library/src/compute/construct.rs b/library/src/compute/construct.rs
index e7e05eee..4ba73a73 100644
--- a/library/src/compute/construct.rs
+++ b/library/src/compute/construct.rs
@@ -45,6 +45,7 @@ cast_from_value! {
///
/// - Booleans are converted to `0.0` or `1.0`.
/// - Integers are converted to the closest 64-bit float.
+/// - Ratios are divided by 100%.
/// - Strings are parsed in base 10 to the closest 64-bit float.
/// Exponential notation is supported.
///
@@ -53,6 +54,7 @@ cast_from_value! {
/// #float(false) \
/// #float(true) \
/// #float(4) \
+/// #float(40%) \
/// #float("2.7") \
/// #float("1e5")
/// ```
@@ -76,6 +78,7 @@ cast_from_value! {
v: bool => Self(v as i64 as f64),
v: i64 => Self(v as f64),
v: f64 => Self(v),
+ v: Ratio => Self(v.get()),
v: EcoString => Self(v.parse().map_err(|_| "not a valid float")?),
}