apache / apache/arrow-rs

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

Open
#10,999 1 comment 0 reactions 1 assignee Claimed by @neilconway View on GitHub
bug
Dominant language
Rust
Stars
3.6k
Forks
1.3k
Avg merge
2d 18h
Merged PRs (30d)
169

Description

### 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

```rust
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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.