@@ -601,9 +601,9 @@ ndigits(x::Integer; base::Integer=10, pad::Integer=1) = max(pad, ndigits0z(x, ba
601
601
602
602
# # integer to string functions ##
603
603
604
- function bin (x:: Unsigned , pad:: Integer , neg:: Bool )
604
+ function bin (x:: Unsigned , pad:: Int , neg:: Bool )
605
605
m = 8 sizeof (x) - leading_zeros (x):: Int
606
- n = neg + max (( pad % Int) :: Int , m)
606
+ n = neg + max (pad, m)
607
607
a = StringVector (n)
608
608
# for i in 0x0:UInt(n-1) # automatic vectorization produces redundant codes
609
609
# @inbounds a[n - i] = 0x30 + (((x >> i) % UInt8)::UInt8 & 0x1)
@@ -628,9 +628,9 @@ function bin(x::Unsigned, pad::Integer, neg::Bool)
628
628
String (a)
629
629
end
630
630
631
- function oct (x:: Unsigned , pad:: Integer , neg:: Bool )
631
+ function oct (x:: Unsigned , pad:: Int , neg:: Bool )
632
632
m = div (8 sizeof (x) - leading_zeros (x):: Int + 2 , 3 )
633
- n = neg + max (( pad % Int) :: Int , m)
633
+ n = neg + max (pad, m)
634
634
a = StringVector (n)
635
635
i = n
636
636
while i > neg
645
645
# 2-digit decimal characters ("00":"99")
646
646
const _dec_d100 = UInt16[(0x30 + i % 10 ) << 0x8 + (0x30 + i ÷ 10 ) for i = 0 : 99 ]
647
647
648
- function dec (x:: Unsigned , pad:: Integer , neg:: Bool )
649
- n = neg + ndigits (x, base= 10 , pad= ( pad % Int) :: Int ):: Int
648
+ function dec (x:: Unsigned , pad:: Int , neg:: Bool )
649
+ n = neg + ( ndigits (x, base= 10 , pad= pad) % Int):: Int
650
650
a = StringVector (n)
651
651
i = n
652
652
@inbounds while i >= 2
@@ -664,9 +664,9 @@ function dec(x::Unsigned, pad::Integer, neg::Bool)
664
664
String (a)
665
665
end
666
666
667
- function hex (x:: Unsigned , pad:: Integer , neg:: Bool )
667
+ function hex (x:: Unsigned , pad:: Int , neg:: Bool )
668
668
m = 2 sizeof (x) - (leading_zeros (x):: Int >> 2 )
669
- n = neg + max (( pad % Int) :: Int , m)
669
+ n = neg + max (pad, m)
670
670
a = StringVector (n)
671
671
i = n
672
672
while i >= 2
@@ -688,12 +688,12 @@ end
688
688
const base36digits = UInt8[' 0' :' 9' ;' a' :' z' ]
689
689
const base62digits = UInt8[' 0' :' 9' ;' A' :' Z' ;' a' :' z' ]
690
690
691
- function _base (base:: Integer , x:: Integer , pad:: Integer , neg:: Bool )
691
+ function _base (base:: Integer , x:: Integer , pad:: Int , neg:: Bool )
692
+ (x >= 0 ) | (base < 0 ) || throw (DomainError (x, " For negative `x`, `base` must be negative." ))
693
+ 2 <= abs (base) <= 62 || throw (DomainError (b, " base must satisfy 2 ≤ abs(base) ≤ 62" ))
692
694
b = (base % Int):: Int
693
- (x >= 0 ) | (b < 0 ) || throw (DomainError (x, " For negative `x`, `base` must be negative." ))
694
- 2 <= abs (b) <= 62 || throw (DomainError (b, " base must satisfy 2 ≤ abs(base) ≤ 62" ))
695
695
digits = abs (b) <= 36 ? base36digits : base62digits
696
- n = neg + ndigits (x, base= b, pad= ( pad % Int) :: Int ):: Int
696
+ n = neg + ( ndigits (x, base= b, pad= pad) % Int):: Int
697
697
a = StringVector (n)
698
698
i = n
699
699
@inbounds while i > neg
@@ -728,6 +728,7 @@ julia> string(13, base = 5, pad = 4)
728
728
```
729
729
"""
730
730
function string (n:: Integer ; base:: Integer = 10 , pad:: Integer = 1 )
731
+ pad = (min (max (pad, typemin (Int)), typemax (Int)) % Int):: Int
731
732
if base == 2
732
733
(n_positive, neg) = split_sign (n)
733
734
bin (n_positive, pad, neg)
0 commit comments