1use super::*;
2
3pub fn int_extension<Buffer: IoWrite>() -> Extension<Buffer> {
4 let mut funcs: AHashMap<String, Arc<ForeignFunction<Buffer>>> = AHashMap::default();
5 funcs.insert(
6 "MAX".to_string(),
7 Arc::new(|_, _, _| Ok(DiatomValue::Int(i64::MAX))),
8 );
9
10 funcs.insert(
11 "MIN".to_string(),
12 Arc::new(|_, _, _| Ok(DiatomValue::Int(i64::MIN))),
13 );
14
15 funcs.insert(
16 "abs".to_string(),
17 Arc::new(|_, parameters, _| {
18 assure_para_len!(parameters, 1);
19 match parameters[0] {
20 DiatomValue::Int(i) => Ok(DiatomValue::Int(i64::wrapping_abs(i))),
21 _ => Err("Expected type `Int`".to_string()),
22 }
23 }),
24 );
25 funcs.insert(
26 "abs".to_string(),
27 Arc::new(|_, parameters, _| {
28 assure_para_len!(parameters, 1);
29 match parameters[0] {
30 DiatomValue::Int(i) => Ok(DiatomValue::Int(i64::wrapping_abs(i))),
31 _ => Err("Expected type `Int`".to_string()),
32 }
33 }),
34 );
35
36 funcs.insert(
37 "float".to_string(),
38 Arc::new(|_, parameters, _| {
39 assure_para_len!(parameters, 1);
40 match parameters[0] {
41 DiatomValue::Int(i) => Ok(DiatomValue::Float(i as f64)),
42 _ => Err("Expected type `Int`".to_string()),
43 }
44 }),
45 );
46
47 Extension {
48 name: "int".to_string(),
49 kind: ExtensionKind::ForeignFunctions(funcs),
50 }
51}