Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json, float parsing error #4361

Open
Holub-Patrik opened this issue Oct 9, 2024 · 0 comments
Open

Json, float parsing error #4361

Holub-Patrik opened this issue Oct 9, 2024 · 0 comments

Comments

@Holub-Patrik
Copy link

Context

When loading a simple json file:

{
  "val": -10.0
}

Using a minimal program as such:

package main

import "core:encoding/json"
import "core:fmt"
import "core:os"

main :: proc() {
    data, ok := os.read_entire_file_from_filename("test.json")
    if !ok {
        fmt.println("Data read incorrectly.")
        return
    }
    defer delete(data)

    json_data, err := json.parse(data)
    if err != .None {
        fmt.println("Json couldn't be parsed")
        return
    }
    defer json.destroy_value(json_data)

    root := json_data.(json.Object)
    value := root["val"].(json.Float)

    fmt.println("Value read:", value)

    value_negative_10: f64 = 10.0 * (-1)
    fmt.println("Value real:", value_negative_10)
}

The output is:

Odin: dev-2024-09:962af780a
OS: Ubuntu 24-04-1 LTS, Linux 6.8.0-45-generic
CPU: AMD Ryzen 7 5800H with Radeon Graphics
RAM : 15388 MiB
Backend: LLVM18.1.8

Expected Behavior

Value read: -10
Value real -10

Current Behavior

Value read: -9.983125437429408
Value real: -10

Info

I do not know enough about the json parsing odin uses and so this could be expected behaviour. I have tested parsing the same json file in python (I know, not a fair comparison) and it correctly parsed this. If this is expected, I am sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant