Skip to content

Conversation

@osa1
Copy link
Member

@osa1 osa1 commented Dec 12, 2025

Currently Int64.toRadixStringUnsigned adds an extra '0' when the result is single digit, e.g. '02' instead of '2'.

To be able to use the standard library toRadixString, we split the number into two halves, then calculate the lowest digit and the rest of the digits separately. With the lowest digit removed, the rest of the digits can be passed as a positive integer to toRadixString. The resulting strings are then concatenated to get the final result.

The problem occurs when the number can be printed as a single digit. In this case the rest of the number is printed as '0', giving us e.g. '02' instead of '2'.

To fix, we return early by calling the standard library toRadixString when the number is positive.

This works because

  • The problem is only when printing single digits (as the lowest digit and the rest are printed separately, and the problem is when the "rest" part is 0)

  • Single-digit numbers need to have high 32-bits as zero (otherwise they'll be negative and printed as many digits, or positive but larger than single digit).

  • When the high 32-bits are all zero, the number is positive, and can be converted to string directly with the standard library signed toRadixString.

Currently this adds an extra '0' when the result is single digit, e.g.
'02' instead of '2'.

To be able to use the standard library `toRadixString`, we split the
number into two halves, then calculate the lowest digit and the rest of
the digits separately. With the lowest digit removed, the rest of the
digits can be passed as a positive integer to `toRadixString`. The
resulting strings are then concatenated to get the final result.

The problem occurs when the number can be printed as a single digit. In
this case the rest of the number can be printed as '0', giving us e.g.
'02' instead of '2'.

To fix, we return early by calling the standard library `toRadixString`
when the high 32 bits are zero.

This works because

- The problem is only when printing single digits (as the lowest digit
  and the rest are printed separately, and the problem is when the
  "rest" part is 0)

- Single-digit numbers need to have high 32-bits as zero (otherwise
  they'll be negative and printed as many digits, or positive but larger
  than single digit).

- When the high 32-bits are all zero, the number is positive, and can be
  converted to string with the standard library signed `toRadixString`.
@osa1 osa1 requested a review from a team as a code owner December 12, 2025 11:49
@osa1 osa1 requested a review from lrhn December 12, 2025 11:49
@github-actions
Copy link

Package publishing

Package Version Status Publish tag (post-merge)
package:args 2.8.0 ready to publish args-v2.8.0
package:async 2.13.1-wip WIP (no publish necessary)
package:characters 1.4.1 already published at pub.dev
package:collection 1.20.0-wip WIP (no publish necessary)
package:convert 3.1.3-wip WIP (no publish necessary)
package:crypto 3.0.7 already published at pub.dev
package:fixnum 1.2.0-wip WIP (no publish necessary)
package:lints 6.1.0-wip WIP (no publish necessary)
package:logging 1.3.1-wip WIP (no publish necessary)
package:os_detect 2.0.4-wip WIP (no publish necessary)
package:path 1.9.2-wip WIP (no publish necessary)
package:platform 3.1.7-wip WIP (no publish necessary)
package:typed_data 1.4.1-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@github-actions
Copy link

github-actions bot commented Dec 12, 2025

PR Health

License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/collection/benchmark/legacy_quicksort.dart

This check can be disabled by tagging the PR with skip-license-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Breaking changes ⚠️
Package Change Current Version New Version Needed Version Looking good?
fixnum Breaking 1.1.1 1.2.0-wip 2.0.0
Got "1.2.0-wip" expected >= "2.0.0" (breaking changes)
⚠️

This check can be disabled by tagging the PR with skip-breaking-check.

Coverage ✔️
File Coverage
pkgs/fixnum/lib/src/int64_native.dart 💚 96 % ⬆️ 0 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants