mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 08:55:40 +01:00
Support pi() function
This commit is contained in:
@@ -184,7 +184,7 @@ Feature support of [sqlite expr syntax](https://www.sqlite.org/lang_expr.html).
|
||||
| log10(X) | Yes | |
|
||||
| log2(X) | Yes | |
|
||||
| mod(X,Y) | Yes | |
|
||||
| pi() | No | |
|
||||
| pi() | Yes | |
|
||||
| pow(X,Y) | Yes | |
|
||||
| power(X,Y) | Yes | |
|
||||
| radians(X) | Yes | |
|
||||
|
||||
@@ -1604,6 +1604,20 @@ pub fn translate_expr(
|
||||
}
|
||||
}
|
||||
Func::Math(math_func) => match math_func.arity() {
|
||||
MathFuncArity::Nullary => {
|
||||
if args.is_some() {
|
||||
crate::bail_parse_error!("{} function with arguments", math_func);
|
||||
}
|
||||
|
||||
program.emit_insn(Insn::Function {
|
||||
constant_mask: 0,
|
||||
start_reg: 0,
|
||||
dest: target_register,
|
||||
func: func_ctx,
|
||||
});
|
||||
Ok(target_register)
|
||||
}
|
||||
|
||||
MathFuncArity::Unary => {
|
||||
let args = if let Some(args) = args {
|
||||
if args.len() != 1 {
|
||||
|
||||
@@ -2492,6 +2492,10 @@ impl Program {
|
||||
}
|
||||
},
|
||||
crate::function::Func::Math(math_func) => match math_func.arity() {
|
||||
MathFuncArity::Nullary => {
|
||||
state.registers[*dest] = OwnedValue::Float(std::f64::consts::PI);
|
||||
}
|
||||
|
||||
MathFuncArity::Unary => {
|
||||
let reg_value = &state.registers[*start_reg];
|
||||
let result = exec_math_unary(reg_value, math_func);
|
||||
@@ -2504,6 +2508,7 @@ impl Program {
|
||||
let result = exec_math_binary(lhs, rhs, math_func);
|
||||
state.registers[*dest] = result;
|
||||
}
|
||||
|
||||
_ => unimplemented!(),
|
||||
},
|
||||
crate::function::Func::Agg(_) => {
|
||||
|
||||
@@ -364,6 +364,11 @@ do_execsql_test bitwise-not-zero {
|
||||
|
||||
set tolerance 1e-13
|
||||
|
||||
do_execsql_test_tolerance pi {
|
||||
SELECT pi()
|
||||
} {3.14159265358979} $tolerance
|
||||
|
||||
|
||||
do_execsql_test_tolerance acos-int {
|
||||
SELECT acos(1)
|
||||
} {0.0} $tolerance
|
||||
|
||||
Reference in New Issue
Block a user