1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use Result;
use Client;
use ;
use Value;
use HashMap;
/// Math common module
///
/// This module provides reusable mathematical utilities that can be used by math-related skills.
///
/// # Examples
///
/// ## Validate and parse numbers
///
/// ```rust
/// use crate::executors::utils::Math;
///
/// let num = Math::validate_number("3.14")?;
/// let integer = Math::validate_integer("42")?;
/// ```
///
/// ## Format numbers with precision
///
/// ```rust
/// use crate::executors::utils::Math;
///
/// let formatted = Math::format_number(3.1415926, 2);
/// assert_eq!(formatted, "3.14");
/// ```
///
/// ## Check if number is within range
///
/// ```rust
/// use crate::executors::utils::Math;
///
/// let is_in_range = Math::in_range(5.0, 0.0, 10.0);
/// assert!(is_in_range);
/// ```
///
/// ## Complete example in a skill
///
/// ```rust
/// use crate::executors::types::Skill;
/// use crate::executors::utils::Math;
///
/// async fn execute(&self, parameters: &HashMap<String, Value>) -> Result<String> {
/// let value = parameters
/// .get("value")
/// .and_then(|v| v.as_str())
/// .ok_or_else(|| anyhow::anyhow!("Missing 'value' parameter"))?;
/// let num = Math::validate_number(value)?;
/// let result = num * 2.0;
/// let precision = parameters
/// .get("precision")
/// .and_then(|v| v.as_u64())
/// .unwrap_or(2);
/// Ok(Math::format_number(result, precision as usize))
/// }
/// ```
/// Validate numeric input
/// Validate integer input
/// Format number with appropriate precision
/// Check if number is within range