@@ -624,6 +624,9 @@ pub trait Display {
624
624
///
625
625
/// The `Octal` trait should format its output as a number in base-8.
626
626
///
627
+ /// For primitive signed integers (`i8` to `i128`, and `isize`),
628
+ /// negative values are formatted as the two’s complement representation.
629
+ ///
627
630
/// The alternate flag, `#`, adds a `0o` in front of the output.
628
631
///
629
632
/// For more information on formatters, see [the module-level documentation][module].
@@ -639,6 +642,8 @@ pub trait Display {
639
642
///
640
643
/// assert_eq!(format!("{:o}", x), "52");
641
644
/// assert_eq!(format!("{:#o}", x), "0o52");
645
+ ///
646
+ /// assert_eq!(format!("{:o}", -16), "37777777760");
642
647
/// ```
643
648
///
644
649
/// Implementing `Octal` on a type:
@@ -671,6 +676,9 @@ pub trait Octal {
671
676
///
672
677
/// The `Binary` trait should format its output as a number in binary.
673
678
///
679
+ /// For primitive signed integers (`i8` to `i128`, and `isize`),
680
+ /// negative values are formatted as the two’s complement representation.
681
+ ///
674
682
/// The alternate flag, `#`, adds a `0b` in front of the output.
675
683
///
676
684
/// For more information on formatters, see [the module-level documentation][module].
@@ -686,6 +694,8 @@ pub trait Octal {
686
694
///
687
695
/// assert_eq!(format!("{:b}", x), "101010");
688
696
/// assert_eq!(format!("{:#b}", x), "0b101010");
697
+ ///
698
+ /// assert_eq!(format!("{:b}", -16), "11111111111111111111111111110000");
689
699
/// ```
690
700
///
691
701
/// Implementing `Binary` on a type:
@@ -719,6 +729,9 @@ pub trait Binary {
719
729
/// The `LowerHex` trait should format its output as a number in hexadecimal, with `a` through `f`
720
730
/// in lower case.
721
731
///
732
+ /// For primitive signed integers (`i8` to `i128`, and `isize`),
733
+ /// negative values are formatted as the two’s complement representation.
734
+ ///
722
735
/// The alternate flag, `#`, adds a `0x` in front of the output.
723
736
///
724
737
/// For more information on formatters, see [the module-level documentation][module].
@@ -734,6 +747,8 @@ pub trait Binary {
734
747
///
735
748
/// assert_eq!(format!("{:x}", x), "2a");
736
749
/// assert_eq!(format!("{:#x}", x), "0x2a");
750
+ ///
751
+ /// assert_eq!(format!("{:x}", -16), "fffffff0");
737
752
/// ```
738
753
///
739
754
/// Implementing `LowerHex` on a type:
@@ -767,6 +782,9 @@ pub trait LowerHex {
767
782
/// The `UpperHex` trait should format its output as a number in hexadecimal, with `A` through `F`
768
783
/// in upper case.
769
784
///
785
+ /// For primitive signed integers (`i8` to `i128`, and `isize`),
786
+ /// negative values are formatted as the two’s complement representation.
787
+ ///
770
788
/// The alternate flag, `#`, adds a `0x` in front of the output.
771
789
///
772
790
/// For more information on formatters, see [the module-level documentation][module].
@@ -782,6 +800,8 @@ pub trait LowerHex {
782
800
///
783
801
/// assert_eq!(format!("{:X}", x), "2A");
784
802
/// assert_eq!(format!("{:#X}", x), "0x2A");
803
+ ///
804
+ /// assert_eq!(format!("{:X}", -16), "FFFFFFF0");
785
805
/// ```
786
806
///
787
807
/// Implementing `UpperHex` on a type:
0 commit comments