Skip to content

Commit cade9cf

Browse files
authored
upgradathon: require 0.7 (#61)
1 parent 9065df3 commit cade9cf

File tree

8 files changed

+32
-44
lines changed

8 files changed

+32
-44
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: julia
33
os:
44
- linux
55
julia:
6-
- 0.6
6+
- 0.7
77
- nightly
88
notifications:
99
email: false

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Primes.jl
22

3-
[![Primes](http://pkg.julialang.org/badges/Primes_0.6.svg)](http://pkg.julialang.org/?pkg=Primes)
43
[![Primes](http://pkg.julialang.org/badges/Primes_0.7.svg)](http://pkg.julialang.org/?pkg=Primes)
54
[![Build Status](https://travis-ci.org/JuliaMath/Primes.jl.svg?branch=master)](https://travis-ci.org/JuliaMath/Primes.jl)
65
[![Windows Build](https://ci.appveyor.com/api/projects/status/ao64pk44lwo0092r/branch/master?svg=true)](https://ci.appveyor.com/project/ararslan/primes-jl/branch/master)

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.6
2-
Compat 0.30.0
1+
julia 0.7-alpha

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
55
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
66
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
77

docs/src/index.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,12 @@ This package provides functions for computing prime numbers in Julia.
44

55
## Installation
66

7-
The package is available for Julia versions 0.4 and up.
7+
The package is available for Julia versions 0.4 and up, but if you are
8+
not using Julia version 0.7 or higher, please read the documentation for the
9+
appropriate realease.
10+
811
To install it, run
912
```julia
1013
Pkg.add("Primes")
1114
```
1215
from the Julia REPL.
13-
14-
## Note
15-
16-
Prior to Julia 0.5, these (or similar) functions were available in Julia's Base module.
17-
Because of this, the symbols from this package are not exported on Julia 0.4 to avoid
18-
naming conflicts.
19-
In this case, the symbols will need to be explicitly imported or called with the prefix
20-
`Primes`.
21-
For example,
22-
```julia
23-
using Primes
24-
import Primes: isprime, primes, primesmask, factor
25-
```
26-
This is not necessary for Julia versions 0.5 or later.

src/Primes.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
# This includes parts that were formerly a part of Julia. License is MIT: http://julialang.org/license
2-
__precompile__()
2+
#__precompile__()
33
module Primes
44

5-
using Compat
6-
using Compat.Iterators: repeated
7-
8-
if isdefined(Base,:isprime)
9-
import Base: isprime, primes, primesmask, factor
10-
else
11-
export isprime, primes, primesmask, factor
12-
end
5+
using Base.Iterators: repeated
136

147
using Base: BitSigned
158
using Base.Checked: checked_neg
169

17-
export ismersenneprime, isrieselprime, nextprime, prevprime, prime, prodfactors, radical, totient
10+
export isprime, primes, primesmask, factor, ismersenneprime, isrieselprime,
11+
nextprime, prevprime, prime, prodfactors, radical, totient
1812

1913
include("factorization.jl")
2014

@@ -344,8 +338,13 @@ Set([2,5])
344338
"""
345339
factor(::Type{D}, n::T) where {T<:Integer, D<:AbstractDict} = factor!(n, D(Dict{T,Int}()))
346340
factor(::Type{A}, n::T) where {T<:Integer, A<:AbstractArray} = A(factor(Vector{T}, n))
347-
factor(::Type{Vector{T}}, n::T) where {T<:Integer} =
348-
mapreduce(collect, vcat, Vector{T}(), [repeated(k, v) for (k, v) in factor(n)])
341+
if VERSION >= v"0.7.0-beta.81"
342+
factor(::Type{Vector{T}}, n::T) where {T<:Integer} =
343+
mapreduce(collect, vcat, [repeated(k, v) for (k, v) in factor(n)], init=Vector{T}())
344+
else
345+
factor(::Type{Vector{T}}, n::T) where {T<:Integer} =
346+
mapreduce(collect, vcat, Vector{T}(), [repeated(k, v) for (k, v) in factor(n)])
347+
end
349348
factor(::Type{S}, n::T) where {T<:Integer, S<:Union{Set,BitSet}} = S(keys(factor(n)))
350349
factor(::Type{T}, n) where {T<:Any} = throw(MethodError(factor, (T, n)))
351350

@@ -436,6 +435,12 @@ function pollardfactors!(n::T, h::AbstractDict{K,Int}) where {T<:Integer,K<:Inte
436435
end
437436
end
438437

438+
if VERSION >= v"0.7.0-beta.183"
439+
ndigits2(n) = ndigits(n, base=2)
440+
else
441+
ndigits2(n) = ndigits(n, 2)
442+
end
443+
439444
"""
440445
ismersenneprime(M::Integer; [check::Bool = true]) -> Bool
441446
@@ -456,7 +461,7 @@ true
456461
"""
457462
function ismersenneprime(M::Integer; check::Bool = true)
458463
if check
459-
d = ndigits(M, 2)
464+
d = ndigits2(M)
460465
M >= 0 && isprime(d) && (M >> d == 0) ||
461466
throw(ArgumentError("The argument given is not a valid Mersenne Number (`M = 2^p - 1`)."))
462467
end
@@ -481,7 +486,7 @@ true
481486
```
482487
"""
483488
function isrieselprime(k::Integer, Q::Integer)
484-
n = ndigits(Q, 2)
489+
n = ndigits2(Q)
485490
0 < k < Q || throw(ArgumentError("The condition 0 < k < Q must be met."))
486491
if k == 1 && isodd(n)
487492
return n % 4 == 3 ? ll_primecheck(Q, 3) : ll_primecheck(Q)
@@ -495,7 +500,7 @@ end
495500

496501
# LL backend -- not for export
497502
function ll_primecheck(X::Integer, s::Integer = 4)
498-
S, N = BigInt(s), BigInt(ndigits(X, 2))
503+
S, N = BigInt(s), BigInt(ndigits2(X))
499504
X < 7 && throw(ArgumentError("The condition X ≥ 7 must be met."))
500505
for i in 1:(N - 2)
501506
S = (S^2 - 2) % X

src/factorization.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
struct Factorization{T<:Integer} <: AbstractDict{T, Int}
55
pe::Vector{Pair{T, Int}} # Prime-Exponent
66

7-
# Factorization{T}() where {T} = new(Vector{Pair{T, Int}}())
87
Factorization{T}() where {T<:Integer} = new{T}(Vector{Pair{T, Int}}())
98
end
109

@@ -14,12 +13,10 @@ function Factorization{T}(d::AbstractDict) where T<:Integer
1413
f
1514
end
1615

17-
Base.convert(::Type{Factorization}, d::AbstractDict{T}) where {T} = Factorization{T}(d)
18-
19-
Base.start(f::Factorization) = start(f.pe)
20-
Base.next(f::Factorization, i) = next(f.pe, i)
21-
Base.done(f::Factorization, i) = done(f.pe, i)
16+
Factorization(d::AbstractDict{T}) where {T<:Integer} = Factorization{T}(d)
17+
Base.convert(::Type{Factorization}, d::AbstractDict) = Factorization(d)
2218

19+
Base.iterate(f::Factorization, state...) = iterate(f.pe, state...)
2320

2421
function Base.get(f::Factorization, p, default)
2522
found = searchsorted(f.pe, p, by=first)

test/runtests.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Primes
2-
using Compat
3-
using Compat.Test
2+
using Test
43
using DataStructures: SortedDict
54

65
import Primes: isprime, primes, primesmask, factor, ismersenneprime, isrieselprime, Factorization

0 commit comments

Comments
 (0)