File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 533
533
534
534
add (n:: BigInt , x:: Int ) = n + x
535
535
add (n:: Integer , x:: Int ) = Base. checked_add (n, oftype (n, x))
536
+ sub (n:: BigInt , x:: Int ) = n - x
537
+ sub (n:: Integer , x:: Int ) = Base. checked_sub (n, oftype (n, x))
536
538
537
539
# add_! : "may" mutate the Integer argument (only for BigInt currently)
538
540
548
550
549
551
# checked addition, without mutation
550
552
add_! (n:: Integer , x:: Int ) = add (n, x)
553
+ sub_! (n:: BigInt , x:: Int ) = add_! (n, - x)
554
+ sub_! (n:: Integer , x:: Int ) = sub (n, x)
551
555
552
556
"""
553
557
nextprime(n::Integer, i::Integer=1; interval::Integer=1)
@@ -662,9 +666,9 @@ function prevprime(n::Integer, i::Integer=1; interval::Integer=1)
662
666
663
667
# A bit ugly, but this lets us skip half of the isprime tests when isodd(interval)
664
668
@inline function decrement (n)
665
- n = add_ ! (n, - interval)
669
+ n = sub_ ! (n, interval)
666
670
iseven (n) && n != 2 ? # n obviously not prime
667
- add_ ! (n, - interval) :
671
+ sub_ ! (n, interval) :
668
672
n
669
673
end
670
674
Original file line number Diff line number Diff line change 360
360
@test prevprime (3 ) == 3
361
361
@test prevprime (3 , 2 ) == 2
362
362
@test prevprime (2 ) == 2
363
+ @test prevprime (typemax (UInt8)) == prevprime (big (typemax (UInt8)))
364
+ @test typeof (prevprime (typemax (UInt8))) === UInt8
363
365
@test_throws ArgumentError prevprime (2 , 2 )
364
366
365
367
@test_throws DomainError prevprime (rand (- 100 : 100 ), 0 )
You can’t perform that action at this time.
0 commit comments