@@ -615,9 +615,9 @@ ndigits(x::Integer; base::Integer=10, pad::Integer=1) = max(pad, ndigits0z(x, ba
615
615
616
616
# # integer to string functions ##
617
617
618
- function bin (x:: Unsigned , pad:: Integer , neg:: Bool )
618
+ function bin (x:: Unsigned , pad:: Int , neg:: Bool )
619
619
m = 8 sizeof (x) - leading_zeros (x):: Int
620
- n = neg + max (( pad % Int) :: Int , m)
620
+ n = neg + max (pad, m)
621
621
a = StringVector (n)
622
622
# for i in 0x0:UInt(n-1) # automatic vectorization produces redundant codes
623
623
# @inbounds a[n - i] = 0x30 + (((x >> i) % UInt8)::UInt8 & 0x1)
@@ -642,9 +642,9 @@ function bin(x::Unsigned, pad::Integer, neg::Bool)
642
642
String (a)
643
643
end
644
644
645
- function oct (x:: Unsigned , pad:: Integer , neg:: Bool )
645
+ function oct (x:: Unsigned , pad:: Int , neg:: Bool )
646
646
m = div (8 sizeof (x) - leading_zeros (x):: Int + 2 , 3 )
647
- n = neg + max (( pad % Int) :: Int , m)
647
+ n = neg + max (pad, m)
648
648
a = StringVector (n)
649
649
i = n
650
650
while i > neg
659
659
# 2-digit decimal characters ("00":"99")
660
660
const _dec_d100 = UInt16[(0x30 + i % 10 ) << 0x8 + (0x30 + i ÷ 10 ) for i = 0 : 99 ]
661
661
662
- function dec (x:: Unsigned , pad:: Integer , neg:: Bool )
663
- n = neg + ndigits (x, base= 10 , pad= ( pad % Int) :: Int ):: Int
662
+ function dec (x:: Unsigned , pad:: Int , neg:: Bool )
663
+ n = neg + ( ndigits (x, base= 10 , pad= pad) % Int):: Int
664
664
a = StringVector (n)
665
665
i = n
666
666
@inbounds while i >= 2
@@ -678,9 +678,9 @@ function dec(x::Unsigned, pad::Integer, neg::Bool)
678
678
String (a)
679
679
end
680
680
681
- function hex (x:: Unsigned , pad:: Integer , neg:: Bool )
681
+ function hex (x:: Unsigned , pad:: Int , neg:: Bool )
682
682
m = 2 sizeof (x) - (leading_zeros (x):: Int >> 2 )
683
- n = neg + max (( pad % Int) :: Int , m)
683
+ n = neg + max (pad, m)
684
684
a = StringVector (n)
685
685
i = n
686
686
while i >= 2
@@ -702,12 +702,12 @@ end
702
702
const base36digits = UInt8[' 0' :' 9' ;' a' :' z' ]
703
703
const base62digits = UInt8[' 0' :' 9' ;' A' :' Z' ;' a' :' z' ]
704
704
705
- function _base (base:: Integer , x:: Integer , pad:: Integer , neg:: Bool )
705
+ function _base (base:: Integer , x:: Integer , pad:: Int , neg:: Bool )
706
+ (x >= 0 ) | (base < 0 ) || throw (DomainError (x, " For negative `x`, `base` must be negative." ))
707
+ 2 <= abs (base) <= 62 || throw (DomainError (base, " base must satisfy 2 ≤ abs(base) ≤ 62" ))
706
708
b = (base % Int):: Int
707
- (x >= 0 ) | (b < 0 ) || throw (DomainError (x, " For negative `x`, `base` must be negative." ))
708
- 2 <= abs (b) <= 62 || throw (DomainError (b, " base must satisfy 2 ≤ abs(base) ≤ 62" ))
709
709
digits = abs (b) <= 36 ? base36digits : base62digits
710
- n = neg + ndigits (x, base= b, pad= ( pad % Int) :: Int ):: Int
710
+ n = neg + ( ndigits (x, base= b, pad= pad) % Int):: Int
711
711
a = StringVector (n)
712
712
i = n
713
713
@inbounds while i > neg
@@ -742,6 +742,7 @@ julia> string(13, base = 5, pad = 4)
742
742
```
743
743
"""
744
744
function string (n:: Integer ; base:: Integer = 10 , pad:: Integer = 1 )
745
+ pad = (min (max (pad, typemin (Int)), typemax (Int)) % Int):: Int
745
746
if base == 2
746
747
(n_positive, neg) = split_sign (n)
747
748
bin (n_positive, pad, neg)
0 commit comments