Skip to content

RADON parses JSON integers as floats, rounding them to a different value #2315

Closed
@tmpolaczyk

Description

@tmpolaczyk

So operators like StringParseJSONArray can only parse integers correctly up to MAX_SAFE_INTEGER, which is 2^53-1.

The following test shows how 2^53+1 is parsed as 2^53:

#[test]
fn test_parse_json_array_max_safe_integer_plus_2() {
    use crate::types::array::RadonArray;
    use crate::types::integer::RadonInteger;
    use crate::types::string::RadonString;

    // 2^53 + 1
    let input = RadonTypes::from(RadonString::from(r#"[9007199254740993]"#));
    let script = vec![(RadonOpCodes::StringParseJSONArray, None)];

    let output = execute_contextfree_radon_script(input, &script).unwrap();

    assert_eq!(
        output,
        RadonTypes::from(RadonArray::from(vec![RadonTypes::from(RadonInteger::from(
            9007199254740993
        ))]))
    );
}

Output:

thread 'script::tests::test_parse_json_array_biggish_integers' panicked at 'assertion failed: `(left == right)`
  left: `Array(RadonArray { value: [Integer(RadonInteger { value: 9007199254740992 })], is_homogeneous: true })`,
 right: `Array(RadonArray { value: [Integer(RadonInteger { value: 9007199254740993 })], is_homogeneous: true })`', rad/src/script.rs:607:9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions