Skip to content

i256 Display and Debug ignore formatter width, fill, alignment and sign flags #10999

Open

Description

@neilconway

Describe the bug

Display for i256 formats the value through a temporary BigInt with write!(f, "{}", bigint), which formats it with a default spec and discards the caller's. Every primitive integer applies the caller's spec through Formatter::pad_integral, and so does num_bigint::BigInt itself, so i256 is the only integer type in the workspace for which {:>8}, {:08}, {:+} and friends are no-ops.

To Reproduce

use arrow_buffer::i256;

assert_eq!(format!("{:>8}", 1_i128), "       1");
assert_eq!(format!("{:>8}", i256::ONE), "1");            // expected "       1"

assert_eq!(format!("{:+}", 1_i128), "+1");
assert_eq!(format!("{:+}", i256::ONE), "1");             // expected "+1"

assert_eq!(format!("{:08}", -42_i128), "-0000042");
assert_eq!(format!("{:08}", i256::from_i128(-42)), "-42"); // expected "-0000042"

assert_eq!(format!("{:*^7}", i256::ONE), "1");           // expected "***1***"
assert_eq!(format!("{:<6?}", i256::ONE), "1");           // expected "1     "

Expected behavior

i256 should honor the same formatting flags as the primitive integers: width, fill and alignment, the + sign flag, and 0 padding, for both Display and Debug.

Additional context

No response

Activity

  1. added theissue type on Sep 5, 2026
  2. added
    bug
    on Sep 5, 2026
  3. neilconway commented on Sep 5, 2026

    @neilconway
    ContributorAuthor

    take

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

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions