ratex_parser/functions/
sqrt.rs1use std::collections::HashMap;
2
3use crate::error::ParseResult;
4use crate::functions::{define_function_full, FunctionContext, FunctionSpec};
5use crate::parse_node::ParseNode;
6
7pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
8 define_function_full(
9 map,
10 &["\\sqrt"],
11 "sqrt",
12 1,
13 1, None,
15 false,
16 false,
17 true,
18 false,
19 false,
20 handle_sqrt,
21 );
22}
23
24fn handle_sqrt(
25 ctx: &mut FunctionContext,
26 args: Vec<ParseNode>,
27 opt_args: Vec<Option<ParseNode>>,
28) -> ParseResult<ParseNode> {
29 let index = opt_args.into_iter().next().flatten();
30 let body = args.into_iter().next().unwrap();
31
32 Ok(ParseNode::Sqrt {
33 mode: ctx.parser.mode,
34 body: Box::new(body),
35 index: index.map(Box::new),
36 loc: None,
37 })
38}