@@ -409,12 +409,12 @@ const powers_of_ten = [
409
409
0x000000e8d4a51000 , 0x000009184e72a000 , 0x00005af3107a4000 , 0x00038d7ea4c68000 ,
410
410
0x002386f26fc10000 , 0x016345785d8a0000 , 0x0de0b6b3a7640000 , 0x8ac7230489e80000 ,
411
411
]
412
- function ndigits0z (x:: Base.BitUnsigned64 )
412
+ function bit_ndigits0z (x:: Base.BitUnsigned64 )
413
413
lz = (sizeof (x)<< 3 )- leading_zeros (x)
414
414
nd = (1233 * lz)>> 12 + 1
415
415
nd -= x < powers_of_ten[nd]
416
416
end
417
- function ndigits0z (x:: UInt128 )
417
+ function bit_ndigits0z (x:: UInt128 )
418
418
n = 0
419
419
while x > 0x8ac7230489e80000
420
420
x = div (x,0x8ac7230489e80000 )
@@ -423,16 +423,20 @@ function ndigits0z(x::UInt128)
423
423
return n + ndigits0z (UInt64 (x))
424
424
end
425
425
426
- ndigits0z (x:: BitSigned ) = ndigits0z (unsigned (abs (x)))
427
-
426
+ ndigits0z (x:: BitSigned ) = bit_ndigits0z (unsigned (abs (x)))
427
+ ndigits0z (x :: BitUnsigned ) = bit_ndigits0z (x)
428
428
ndigits0z (x:: Integer ) = ndigits0zpb (x, 10 )
429
429
430
430
# # ndigits with specified base ##
431
431
432
432
# The suffix "nb" stands for "negative base"
433
433
function ndigits0znb (x:: Integer , b:: Integer )
434
- # precondition: b < -1 && !(typeof(x) <: Unsigned)
435
434
d = 0
435
+ if x isa Unsigned
436
+ d += (x != 0 ):: Bool
437
+ x = - signed (fld (x, - b))
438
+ end
439
+ # precondition: b < -1 && !(typeof(x) <: Unsigned)
436
440
while x != 0
437
441
x = cld (x,b)
438
442
d += 1
@@ -441,7 +445,6 @@ function ndigits0znb(x::Integer, b::Integer)
441
445
end
442
446
443
447
# do first division before conversion with signed here, which can otherwise overflow
444
- ndigits0znb (x:: Unsigned , b:: Integer ) = ndigits0znb (- signed (fld (x, - b)), b) + (x != 0 )
445
448
ndigits0znb (x:: Bool , b:: Integer ) = x % Int
446
449
447
450
# The suffix "pb" stands for "positive base"
@@ -451,11 +454,11 @@ function ndigits0zpb(x::Integer, b::Integer)
451
454
b = Int (b)
452
455
x = abs (x)
453
456
if x isa Base. BitInteger
454
- x = unsigned (x)
457
+ x = unsigned (x):: Unsigned
455
458
b == 2 && return sizeof (x)<< 3 - leading_zeros (x)
456
459
b == 8 && return (sizeof (x)<< 3 - leading_zeros (x) + 2 ) ÷ 3
457
460
b == 16 && return sizeof (x)<< 1 - leading_zeros (x)>> 2
458
- b == 10 && return ndigits0z (x)
461
+ b == 10 && return bit_ndigits0z (x)
459
462
end
460
463
461
464
d = 0
@@ -595,7 +598,7 @@ const base62digits = ['0':'9';'A':'Z';'a':'z']
595
598
596
599
function _base (b:: Integer , x:: Integer , pad:: Integer , neg:: Bool )
597
600
(x >= 0 ) | (b < 0 ) || throw (DomainError (x, " For negative `x`, `b` must be negative." ))
598
- 2 <= abs (b) <= 62 || throw (ArgumentError ( " base must satisfy 2 ≤ abs(base) ≤ 62, got $b " ))
601
+ 2 <= abs (b) <= 62 || throw (DomainError (b, " base must satisfy 2 ≤ abs(base) ≤ 62" ))
599
602
digits = abs (b) <= 36 ? base36digits : base62digits
600
603
i = neg + ndigits (x, base= b, pad= pad)
601
604
a = StringVector (i)
@@ -745,7 +748,7 @@ julia> digits!([2,2,2,2,2,2], 10, base = 2)
745
748
```
746
749
"""
747
750
function digits! (a:: AbstractVector{T} , n:: Integer ; base:: Integer = 10 ) where T<: Integer
748
- 2 <= abs (base) || throw (ArgumentError ( " base must be ≥ 2 or ≤ -2, got $base " ))
751
+ 2 <= abs (base) || throw (DomainError (base, " base must be ≥ 2 or ≤ -2" ))
749
752
hastypemax (T) && abs (base) - 1 > typemax (T) &&
750
753
throw (ArgumentError (" type $T too small for base $base " ))
751
754
isempty (a) && return a
2 commit comments
nanosoldier commentedon Feb 8, 2019
Executing the daily benchmark build, I will reply here when finished:
@nanosoldier
runbenchmarks(ALL, isdaily = true)
nanosoldier commentedon Feb 8, 2019
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan