10000 fix floating-point precision issue in arxml 'parse_number_string' by sfpetersen · Pull Request #711 · cantools/cantools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix floating-point precision issue in arxml 'parse_number_string' #711

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

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

sfpetersen
Copy link
Contributor
@sfpetersen sfpetersen commented Nov 27, 2024

Currently, the arxml parse_number_string utils function parses numeric values as a float first, and converts to integer if an integer is required. For very large integers, floating-point error causes the integer to be parsed incorrectly.

>>> int(2**64 -1)
18446744073709551615
>>> int(float(2**64 -1))
18446744073709551616

This pull request orders the parsing attempts to prevent using float at all for parsing integer strings when possible.

@coveralls
Copy link
coveralls commented Nov 27, 2024

Pull Request Test Coverage Report for Build 12041571440

Details

  • 5 of 6 (83.33%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 93.582%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/cantools/database/can/formats/arxml/utils.py 3 4 75.0%
Totals Coverage Status
Change from base Build 11933832730: -0.01%
Covered Lines: 7262
Relevant Lines: 7760

💛 - Coveralls

@andlaus
Copy link
Member
andlaus commented Nov 27, 2024

I have no objections and the tests pass. merging...

@andlaus andlaus merged commit b766c6d into cantools:master Nov 27, 2024
19 checks passed
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

Successfully merging this pull request may close these issues.

3 participants
0