Files
RustPython/Lib
Changjoon c2910c06f3 Round float at the decimal level to match CPython's _Py_dg_dtoa (#7761)
* Round float at the decimal level to match CPython's _Py_dg_dtoa

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. For example, 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.
Replace the multiply-then-round step with `format!` + `parse` for
ndigits >= 0. The ndigits < 0 path is unchanged because dividing
typical inputs by 10**|ndigits| produces genuine ties rather than
synthesizing them.

Verified byte-identical with CPython 3.14.4 over a 108-case random
fuzz plus targeted half-tie probes. Unmasks
`test_float.RoundTestCase.test_matches_float_format` and
`test_previous_round_bugs`.

* Use #[expect] with reason for float_cmp suppression

Co-authored-by: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com>

---------

Co-authored-by: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com>
2026-05-03 00:16:27 +09:00
..
2025-04-11 09:30:58 +09:00
2026-02-02 00:43:07 +09:00
2026-02-18 03:09:55 +09:00
2026-02-06 12:05:17 +09:00
2026-01-17 19:22:00 +09:00
2026-04-14 21:02:25 +09:00
2026-02-05 00:21:34 +09:00
2026-01-18 19:16:48 +09:00
2026-01-20 15:29:05 +09:00
2026-01-17 19:21:11 +09:00
2026-03-02 01:24:15 +09:00
2025-04-06 17:21:28 +09:00
2026-01-17 19:21:10 +09:00
2026-02-27 09:44:41 +01:00
2026-02-14 18:18:53 +02:00
2026-03-01 20:51:10 +09:00
2025-03-20 14:28:26 +09:00
2025-03-10 11:43:53 +09:00
2026-02-02 01:20:23 +09:00
2025-01-11 18:48:27 +09:00
2025-03-10 11:43:53 +09:00
2025-03-10 23:13:32 -07:00
2026-01-30 16:38:36 +02:00
2026-02-13 14:13:30 +09:00
2026-02-13 13:55:05 +09:00
2026-02-24 01:07:30 +00:00
2026-01-30 19:21:10 +09:00
2026-02-02 01:20:23 +09:00
2026-01-19 00:04:06 +09:00
2026-02-28 12:09:59 +09:00
2026-01-31 10:11:58 +09:00
2025-04-21 20:45:06 -07:00
2026-01-24 00:24:12 +09:00
2026-02-18 00:43:49 +09:00
2026-02-24 01:07:30 +00:00
2026-01-30 16:38:36 +02:00
2026-02-08 20:36:35 +09:00
2026-01-26 10:40:22 +09:00
2026-02-11 16:47:03 +09:00
2026-02-15 00:38:01 +09:00
2025-04-30 14:33:52 +09:00
2026-01-30 07:48:29 +09:00
2026-01-20 17:32:52 +09:00
2026-02-08 16:35:56 +09:00
2026-02-08 16:35:56 +09:00
2026-02-14 21:40:04 +09:00
2026-02-15 21:04:32 +09:00
2026-02-13 14:13:30 +09:00
2026-02-09 12:56:53 +09:00
2026-03-06 06:00:08 +09:00
2026-02-14 18:19:57 +02:00
2026-01-21 20:14:30 +09:00
2026-01-25 00:18:55 +09:00
2026-01-25 00:18:55 +09:00
2026-03-01 14:51:54 +09:00
2026-01-23 23:57:31 +09:00
2026-02-03 22:10:31 +09:00
2026-02-11 16:50:23 +09:00
2026-02-05 19:27:10 +09:00
2026-03-03 20:00:50 +09:00
2026-03-12 18:08:56 +09:00
2026-02-13 20:24:57 +09:00
2026-02-06 01:14:55 +09:00
2025-07-25 10:50:17 +09:00
2026-02-13 18:07:25 +09:00
2026-02-04 18:32:45 +09:00
2026-02-28 22:50:51 +09:00
2019-07-16 19:13:07 -05:00
2026-01-21 15:10:40 +09:00
2025-04-21 21:11:42 -07:00
2025-07-17 00:04:12 +09:00
2026-02-15 09:02:24 +09:00
2024-04-26 01:39:02 +09:00
2026-01-17 19:21:10 +09:00
2026-03-04 17:47:40 +09:00
2024-03-22 14:54:02 +09:00
2024-03-22 14:54:02 +09:00
2026-03-01 11:36:46 +09:00
2026-02-14 09:18:09 +09:00
2026-02-11 18:01:41 +09:00
2026-01-21 03:05:05 +09:00
2026-01-30 19:13:59 +02:00
2026-02-27 16:53:55 +09:00
2019-06-22 13:13:34 +02:00
2026-01-22 08:02:43 +09:00
2026-03-10 11:28:16 +09:00
2026-03-04 05:38:58 +09:00
2026-02-18 17:19:49 +09:00
2026-02-13 13:42:22 +09:00
2026-01-30 19:21:10 +09:00
2026-03-05 17:25:59 +09:00

Standard Library for RustPython

This directory contains all of the Python files that make up the standard library for RustPython.

Most of these files are copied over from the CPython repository (the 3.7 branch), with slight modifications to allow them to work under RustPython. The current goal is to complete the standard library with as few modifications as possible. Current modifications are just temporary workarounds for bugs/missing feature within the RustPython implementation.

The first big module we are targeting is unittest, so we can leverage the CPython test suite.