mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
printf truncates floats
This commit is contained in:
@@ -65,9 +65,12 @@ pub fn exec_printf(values: &[Register]) -> crate::Result<Value> {
|
||||
return Err(LimboError::InvalidArgument("not enough arguments".into()));
|
||||
}
|
||||
let value = &values[args_index].get_value();
|
||||
match value {
|
||||
Value::Integer(_) => result.push_str(&format!("{value}")),
|
||||
Value::Float(_) => result.push_str(&format!("{value}")),
|
||||
match value {
|
||||
Value::Integer(i) => result.push_str(&format!("{}", i)),
|
||||
Value::Float(f) => {
|
||||
let truncated_val = *f as i64;
|
||||
result.push_str(&format!("{}", truncated_val));
|
||||
}
|
||||
_ => result.push('0'),
|
||||
}
|
||||
args_index += 1;
|
||||
@@ -311,6 +314,11 @@ mod tests {
|
||||
vec![text("Number: %d"), text("not a number")],
|
||||
text("Number: 0"),
|
||||
),
|
||||
|
||||
(
|
||||
vec![text("Truncated float: %d"), float(3.9)],
|
||||
text("Truncated float: 3"),
|
||||
),
|
||||
(vec![text("Number: %i"), integer(42)], text("Number: 42")),
|
||||
];
|
||||
for (input, output) in test_cases {
|
||||
|
||||
@@ -220,3 +220,8 @@ do_execsql_test_error_content select-nested-agg-func {
|
||||
do_execsql_test_error_content select-nested-agg-func-in-expression {
|
||||
SELECT CASE WHEN max(abs(sum(age))) > 0 THEN 1 ELSE 0 END, sum(age) FROM users;
|
||||
} {"misuse of aggregate function"}
|
||||
|
||||
# https://github.com/tursodatabase/turso/issues/3308
|
||||
do_execsql_test printf-19029102 {
|
||||
select printf('%d', 3.9);
|
||||
} {3}
|
||||
|
||||
Reference in New Issue
Block a user