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

output of json encode/decode of structs containing f64 arrays is not equivalent to the input #22860

Open
holder66 opened this issue Nov 14, 2024 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Status: Confirmed This bug has been confirmed to be valid by a contributor.

Comments

@holder66
Copy link

holder66 commented Nov 14, 2024

Describe the bug

Applying json.encode and then json.decode to a struct containing an f64 array generates an output which is no longer equivalent to the input.
It appears to be related to how and where rounding is done.

Reproduction Steps

module main

import json

struct Test {
mut:
	arr []f64
}

fn main() {
	mut a := Test{}
	a.arr = [0.9716157205240175, 0.9336099585062241]
	println(a)
	mut enc := json.encode(a)
	println(enc)
	println(json.decode(Test, enc)!)
	println(a == json.decode(Test, enc)!)
}

Expected Behavior

the input should be equivalent to the output

Current Behavior

Test{
    arr: [0.9716157205240175, 0.9336099585062241]
}
{"arr":[0.97161572052401746,0.933609958506224]}
Test{
    arr: [0.9716157205240175, 0.933609958506224]
}
false

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 df51e84, timestamp: 2024-11-14 13:58:50 +0200

Environment details (OS name and version, etc.)

V full version: V 0.4.8 dad8e3c.df51e84
OS: macos, macOS, 15.0.1, 24A348
Processor: 16 cpus, 64bit, little endian, Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz

getwd: /Users/henryolders
vexe: /Users/henryolders/v/v
vexe mtime: 2024-11-14 15:14:24

vroot: OK, value: /Users/henryolders/v
VMODULES: OK, value: /Users/henryolders/.vmodules
VTMP: OK, value: /tmp/v_507

env VFLAGS: "-use-os-system-to-run"

Git version: git version 2.47.0
Git vroot status: weekly.2024.06-1635-gdf51e840
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.4)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-amd64 975f1ad8

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@holder66 holder66 added the Bug This tag is applied to issues which reports bugs. label Nov 14, 2024
@JalonSolov JalonSolov added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Nov 14, 2024
@felipensp felipensp added the Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Status: Confirmed This bug has been confirmed to be valid by a contributor.
Projects
None yet
Development

No branches or pull requests

3 participants