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

serde_test floats close values are not possible to test for. #28

Closed
meltinglava opened this issue Apr 14, 2020 · 1 comment
Closed

serde_test floats close values are not possible to test for. #28

meltinglava opened this issue Apr 14, 2020 · 1 comment

Comments

@meltinglava
Copy link

I want to check that a serialization an f64 that is stored in radians to degrees. When i convert into and from radians, there is a minor expected difference in the value.
Example: panicked at 'expected Token::F64(59.949999999999996) but serialized as F64(59.95)
Could not figure out how to fix this.

@dtolnay
Copy link
Member

dtolnay commented Jul 5, 2020

I think you would need to put the computation in the test to match the computation that you expect the Serialize impl(s) to perform, i.e. instead of Token::F64(/* float literal */) you would specify Token::F64(/* the arithmetic computation */). This way the float will match exactly if the Serialize impl is performing the computation that you expect.

@dtolnay dtolnay closed this as completed Jul 5, 2020
@dtolnay dtolnay transferred this issue from serde-rs/serde Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants