You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Positive integers are read as uint type, and negative integers are read as sint type. So is_sint(uint_val) returns false.
I recommend using yyjson_is_int(val) instead, which returns true for both uint and sint types.
Describe the bug
yyjson_is_sint()
returns false for positive integersYour environment
Additional context
I assume this is related to #152.
I wrote a few quick tests:
json = "123"; doc = yyjson_read(json, strlen(json), 0); val = yyjson_doc_get_root(doc); yy_assert(validate_val_type(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_UINT)); yy_assert(strcmp(yyjson_get_type_desc(val), "uint") == 0); yy_assert(yyjson_get_uint(val) == (u64)123); + yy_assert(yyjson_is_sint(val)); yy_assert(yyjson_get_sint(val) == (i64)123); yy_assert(yyjson_get_int(val) == (i64)123); yy_assert(yyjson_get_real(val) == (f64)0); yy_assert(yyjson_get_num(val) == (f64)123); yy_assert(yyjson_get_bool(val) == false); yyjson_doc_free(doc);
json = "-123"; doc = yyjson_read(json, strlen(json), 0); val = yyjson_doc_get_root(doc); yy_assert(validate_val_type(val, YYJSON_TYPE_NUM, YYJSON_SUBTYPE_SINT)); yy_assert(strcmp(yyjson_get_type_desc(val), "sint") == 0); yy_assert(yyjson_get_uint(val) == (u64)-123); + yy_assert(yyjson_is_sint(val)); yy_assert(yyjson_get_sint(val) == (i64)-123); yy_assert(yyjson_get_int(val) == (i64)-123); yy_assert(yyjson_get_real(val) == (f64)0); yy_assert(yyjson_get_num(val) == (f64)-123); yyjson_doc_free(doc);
The
123
variant fails, while the-123
variant passes.The text was updated successfully, but these errors were encountered: