René's URL Explorer Experiment


Title: Round float at the decimal level to match CPython's _Py_dg_dtoa by changjoon-park · Pull Request #7761 · RustPython/RustPython · GitHub

Open Graph Title: Round float at the decimal level to match CPython's _Py_dg_dtoa by changjoon-park · Pull Request #7761 · RustPython/RustPython

X Title: Round float at the decimal level to match CPython's _Py_dg_dtoa by changjoon-park · Pull Request #7761 · RustPython/RustPython

Description: Summary CPython's float.__round__ (Objects/floatobject.c) routes through _Py_dg_dtoa and rounds at the decimal level. The previous round_float_digits multiplied by 10**ndigits and rounded at the IEEE 754 binary level, which diverges for values that aren't exactly representable. >>> round(2.675, 2) # CPython 3.14.4: 2.67 # RustPython main: 2.68 ❌ 2.675 stores as 2.67499...; dtoa correctly rounds it down to 2.67, but (2.675 * 100.0).round() / 100.0 lands on 2.68 because the multiplication produces a phantom 267.5 tie that round-half-to-even snaps up. Rust's {:.*} float formatting uses dtoa-style algorithms (Grisu3 + Dragon4 fallback) and matches CPython's _Py_dg_dtoa byte-for-byte. Replacing the multiply-then-round step with format!("{:.*}", ndigits, x).parse() removes the entire phantom-tie class for ndigits >= 0. For ndigits < 0 the existing divide-then-round path is preserved because dividing typical inputs by 10**|ndigits| produces genuine half-integer ties rather than synthesizing them. Verification (CPython 3.14.4) Probe set Cases Match Targeted half-tie probes (positive ndigits) 34 34/34 Negative ndigits regression 17 17/17 Special values (NaN, ±Inf, ±0.0, NDIGITS bounds) 12 12/12 No-arg round(x) (different code path) 10 10/10 Subnormal / denormal 6 6/6 Random fuzz (mantissa × ndigits ∈ {-5..50}) 4332 4332/4332 Tests unmasked Lib/test/test_float.py::RoundTestCase: test_matches_float_format — rounds against float(format(x, '.{n}f')) across many values; this is exactly what the fix does internally. test_previous_round_bugs — explicit "round-half-even" cases (e.g. round(25.0, -1) == 20.0). Test runs cargo run --release -- -m test test_float test_builtin test_decimal \ test_fractions test_complex test_math test_format test_long test_int \ test_statistics test_re 1573 tests pass, 0 regressions. All 188 extra_tests/snippets/*.py pass under the CI feature set (stdlib,importlib,stdio,encodings,sqlite,ssl-rustls,host_env). A regression block is added to extra_tests/snippets/builtin_round.py. Summary by CodeRabbit Bug Fixes Improved rounding to more closely match CPython’s behavior: better handling of halfway ties (banker’s rounding), negative ndigits, signed zeros, and non-finite inputs. Tests Expanded rounding tests to cover banker's rounding, negative ndigits, exact-half cases, NaN/infinity behavior, signed zero, and out-of-range ndigits.

Open Graph Description: Summary CPython's float.__round__ (Objects/floatobject.c) routes through _Py_dg_dtoa and rounds at the decimal level. The previous round_float_digits multiplied by 10**ndigits and rounded at th...

X Description: Summary CPython&#39;s float.__round__ (Objects/floatobject.c) routes through _Py_dg_dtoa and rounds at the decimal level. The previous round_float_digits multiplied by 10**ndigits and rounded a...

Opengraph URL: https://github.com/RustPython/RustPython/pull/7761

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:943ba585-3b4a-cac2-7f67-12a276f88ad6
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAC16:19AA62:38DE8A8:4831032:6B01F3BD
html-safe-nonce2baa28e6990d77308ab0f7cfd9ec4d9618634cab32c9c8519dc1bb61adfda7b7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzE2OjE5QUE2MjozOERFOEE4OjQ4MzEwMzI6NkIwMUYzQkQiLCJ2aXNpdG9yX2lkIjoiODg1MjUwNjQwNTgyMzk2ODE4OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacea717c834a49515428d612ba793c046f2fe803cb9a994d5d520502306451e0a4
hovercard-subject-tagpull_request:3617637430
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/7761/files
twitter:imagehttps://avatars.githubusercontent.com/u/131537123?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/131537123?s=400&v=4
og:image:altSummary CPython's float.__round__ (Objects/floatobject.c) routes through _Py_dg_dtoa and rounds at the decimal level. The previous round_float_digits multiplied by 10**ndigits and rounded at th...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/pull/7761/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F7761%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F7761%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/pull/7761/files
Reloadhttps://github.com/RustPython/RustPython/pull/7761/files
Reloadhttps://github.com/RustPython/RustPython/pull/7761/files
RustPythonhttps://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Codehttps://github.com/RustPython/RustPython
Issues195 (195)https://github.com/RustPython/RustPython/issues
Pull requests133 (133)https://github.com/RustPython/RustPython/pulls
Discussionshttps://github.com/RustPython/RustPython/discussions
Actionshttps://github.com/RustPython/RustPython/actions
Projectshttps://github.com/RustPython/RustPython/projects
Wikihttps://github.com/RustPython/RustPython/wiki
Security and qualityhttps://github.com/RustPython/RustPython/security
Insightshttps://github.com/RustPython/RustPython/insights
Sign up for GitHub https://github.com/signup?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
youknowonehttps://github.com/youknowone
RustPython:mainhttps://github.com/RustPython/RustPython/tree/main
changjoon-park:fix-round-float-digits-dtoahttps://github.com/changjoon-park/RustPython/tree/fix-round-float-digits-dtoa
Conversation 7 https://github.com/RustPython/RustPython/pull/7761
Commits 2 https://github.com/RustPython/RustPython/pull/7761/commits
Checks 20 https://github.com/RustPython/RustPython/pull/7761/checks
Files changed https://github.com/RustPython/RustPython/pull/7761/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7761/files
Round float at the decimal level to match CPython's _Py_dg_dtoa https://github.com/RustPython/RustPython/pull/7761/files#top
Show all changes 2 commits https://github.com/RustPython/RustPython/pull/7761/files
2310495 Round float at the decimal level to match CPython's _Py_dg_dtoa changjoon-park May 2, 2026 https://github.com/RustPython/RustPython/pull/7761/commits/23104959b142453ca556c54b1889ec8e729ce301
f039f28 Use #[expect] with reason for float_cmp suppression changjoon-park May 2, 2026 https://github.com/RustPython/RustPython/pull/7761/commits/f039f288ea974d30b4fe1e98a3f4ab43bc3a7a84
Clear filters https://github.com/RustPython/RustPython/pull/7761/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7761/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7761/files
test_float.py https://github.com/RustPython/RustPython/pull/7761/files#diff-101957dfb9ef9c3a34ad39d7ad89a2d7d69290980553f9425acda0d5633ad453
float_ops.rs https://github.com/RustPython/RustPython/pull/7761/files#diff-db5a7b1448121cad70d180d9bf4ffab697b3faf07904d72367c3647910aff734
builtin_round.py https://github.com/RustPython/RustPython/pull/7761/files#diff-ca7c123116cfadee0be97267e30ce13b620eaba4371e0420bb18b60f7ca56547
Lib/test/test_float.pyhttps://github.com/RustPython/RustPython/pull/7761/files#diff-101957dfb9ef9c3a34ad39d7ad89a2d7d69290980553f9425acda0d5633ad453
View file https://github.com/changjoon-park/RustPython/blob/f039f288ea974d30b4fe1e98a3f4ab43bc3a7a84/Lib/test/test_float.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7761/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7761/files#diff-101957dfb9ef9c3a34ad39d7ad89a2d7d69290980553f9425acda0d5633ad453
https://github.com/RustPython/RustPython/pull/7761/files#diff-101957dfb9ef9c3a34ad39d7ad89a2d7d69290980553f9425acda0d5633ad453
https://github.com/RustPython/RustPython/pull/7761/files#diff-101957dfb9ef9c3a34ad39d7ad89a2d7d69290980553f9425acda0d5633ad453
crates/common/src/float_ops.rshttps://github.com/RustPython/RustPython/pull/7761/files#diff-db5a7b1448121cad70d180d9bf4ffab697b3faf07904d72367c3647910aff734
View file https://github.com/changjoon-park/RustPython/blob/f039f288ea974d30b4fe1e98a3f4ab43bc3a7a84/crates/common/src/float_ops.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7761/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7761/files#diff-db5a7b1448121cad70d180d9bf4ffab697b3faf07904d72367c3647910aff734
https://github.com/RustPython/RustPython/pull/7761/files#diff-db5a7b1448121cad70d180d9bf4ffab697b3faf07904d72367c3647910aff734
extra_tests/snippets/builtin_round.pyhttps://github.com/RustPython/RustPython/pull/7761/files#diff-ca7c123116cfadee0be97267e30ce13b620eaba4371e0420bb18b60f7ca56547
View file https://github.com/changjoon-park/RustPython/blob/f039f288ea974d30b4fe1e98a3f4ab43bc3a7a84/extra_tests/snippets/builtin_round.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/7761/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/7761/files#diff-ca7c123116cfadee0be97267e30ce13b620eaba4371e0420bb18b60f7ca56547
https://github.com/RustPython/RustPython/pull/7761/files#diff-ca7c123116cfadee0be97267e30ce13b620eaba4371e0420bb18b60f7ca56547
Please reload this pagehttps://github.com/RustPython/RustPython/pull/7761/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.