mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-27 01:36:32 +02:00
fix NaN in vec_to_json
This commit is contained in:
parent
a6b055ea39
commit
79d6ea1aea
1 changed files with 9 additions and 1 deletions
10
sqlite-vec.c
10
sqlite-vec.c
|
|
@ -1184,7 +1184,14 @@ static void vec_to_json(sqlite3_context *context, int argc,
|
||||||
sqlite3_str_appendall(str, ",");
|
sqlite3_str_appendall(str, ",");
|
||||||
}
|
}
|
||||||
if (elementType == SQLITE_VEC_ELEMENT_TYPE_FLOAT32) {
|
if (elementType == SQLITE_VEC_ELEMENT_TYPE_FLOAT32) {
|
||||||
sqlite3_str_appendf(str, "%f", ((f32 *)vector)[i]);
|
f32 value = ((f32 *)vector)[i];
|
||||||
|
if(isnan(value)) {
|
||||||
|
sqlite3_str_appendall(str, "null");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sqlite3_str_appendf(str, "%f", value);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (elementType == SQLITE_VEC_ELEMENT_TYPE_INT8) {
|
} else if (elementType == SQLITE_VEC_ELEMENT_TYPE_INT8) {
|
||||||
sqlite3_str_appendf(str, "%d", ((i8 *)vector)[i]);
|
sqlite3_str_appendf(str, "%d", ((i8 *)vector)[i]);
|
||||||
} else if (elementType == SQLITE_VEC_ELEMENT_TYPE_BIT) {
|
} else if (elementType == SQLITE_VEC_ELEMENT_TYPE_BIT) {
|
||||||
|
|
@ -1197,6 +1204,7 @@ static void vec_to_json(sqlite3_context *context, int argc,
|
||||||
char *s = sqlite3_str_finish(str);
|
char *s = sqlite3_str_finish(str);
|
||||||
if (s) {
|
if (s) {
|
||||||
sqlite3_result_text(context, s, len, sqlite3_free);
|
sqlite3_result_text(context, s, len, sqlite3_free);
|
||||||
|
sqlite3_result_subtype(context, JSON_SUBTYPE);
|
||||||
} else {
|
} else {
|
||||||
sqlite3_result_error_nomem(context);
|
sqlite3_result_error_nomem(context);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue