Skip to content

Commit 9f7b181

Browse files
Adding log10 moonblade function
1 parent 68a97b3 commit 9f7b181

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

docs/moonblade/functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ add(trim(name) | len, 2) - Can be used anywhere
124124
- **idiv**(*x*, *y*) -> `number`: Integer division of two numbers.
125125
- **floor**(*x*) -> `number`: Return the smallest integer lower than or equal to x.
126126
- **log**(*x*) -> `number`: Return the natural logarithm of x.
127+
- **log10**(*x*) -> `number`: Return the base 10 logarithm of x.
127128
- **max**(*x*, *y*, *\*n*) -> `number`: Return the maximum number.
128129
- **max**(*list_of_numbers*) -> `number`: Return the maximum number.
129130
- **min**(*x*, *y*, *\*n*) -> `number`: Return the minimum number.

src/moonblade/doc/functions.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,23 @@
5656
"returns": "number",
5757
"help": "Return the natural logarithm of x."
5858
},
59+
{
60+
"name": "log10",
61+
"arguments": ["x"],
62+
"returns": "number",
63+
"help": "Return the base 10 logarithm of x."
64+
},
5965
{
6066
"name": "max",
6167
"arguments": ["x", "y", "*n"],
62-
"alternatives": [
63-
["list_of_numbers"]
64-
],
68+
"alternatives": [["list_of_numbers"]],
6569
"returns": "number",
6670
"help": "Return the maximum number."
6771
},
6872
{
6973
"name": "min",
7074
"arguments": ["x", "y", "*n"],
71-
"alternatives": [
72-
["list_of_numbers"]
73-
],
75+
"alternatives": [["list_of_numbers"]],
7476
"returns": "number",
7577
"help": "Return the minimum number."
7678
},
@@ -248,9 +250,7 @@
248250
{
249251
"name": "fmt",
250252
"arguments": ["string", "*replacements"],
251-
"alternatives": [
252-
["string", "map"]
253-
],
253+
"alternatives": [["string", "map"]],
254254
"returns": "string",
255255
"help": "Format a string by replacing \"{}\" occurrences by subsequent arguments.\n\nExample: `fmt(\"Hello {} {}\", name, surname)` will replace the first \"{}\" by the value of the name column, then the second one by the value of the surname column.\n\nCan also be given a substitution map like so:\n`fmt(\"Hello {name}\", {name: \"John\"})`."
256256
},

src/moonblade/functions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ pub fn get_function(name: &str) -> Option<(Function, FunctionArguments)> {
133133
|args| unary_arithmetic_op(args, DynamicNumber::ln),
134134
FunctionArguments::unary(),
135135
),
136+
"log10" => (
137+
|args| unary_arithmetic_op(args, DynamicNumber::log10),
138+
FunctionArguments::unary(),
139+
),
136140
"lower" => (lower, FunctionArguments::unary()),
137141
"lru" => (lru, FunctionArguments::unary()),
138142
"ltrim" => (ltrim, FunctionArguments::with_range(1..=2)),

src/moonblade/types/dynamic_number.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ impl DynamicNumber {
117117
self.map_float(f64::ln)
118118
}
119119

120+
pub fn log10(self) -> Self {
121+
self.map_float(f64::log10)
122+
}
123+
120124
pub fn exp(self) -> Self {
121125
self.map_float(f64::exp)
122126
}

0 commit comments

Comments
 (0)