Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

itrunc -> trunc, etc, fix Int128 vs float comparisons #9133

Merged
merged 5 commits into from
Nov 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ Deprecated or removed

* `{...}` syntax is deprecated in favor of `Any[...]` ([#8578]).

* `itrunc`, `ifloor`, `iceil` and `iround` are deprecated in favour of
`trunc{T<:Integer}(T,x)`, `floor{T<:Integer}(T,x)`, etc.. `trunc` is now
always bound-checked;`Base.unsafe_trunc` provides the old unchecked `itrunc`
behaviour ([#9133]).


Julia v0.3.0 Release Notes
==========================

Expand Down
10 changes: 5 additions & 5 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ function randsubseq!(S::AbstractArray, A::AbstractArray, p::Real)
empty!(S)
p == 0 && return S
nexpected = p * length(A)
sizehint(S, iround(nexpected + 5*sqrt(nexpected)))
sizehint(S, round(Int,nexpected + 5*sqrt(nexpected)))
if p > 0.15 # empirical threshold for trivial O(n) algorithm to be better
for i = 1:n
rand() <= p && push!(S, A[i])
Expand All @@ -1396,14 +1396,14 @@ function randsubseq!(S::AbstractArray, A::AbstractArray, p::Real)
# s==k (k > 0) is (1-p)^(k-1) * p, and hence the probability (CDF) that
# s is in {1,...,k} is 1-(1-p)^k = F(k). Thus, we can draw the skip s
# from this probability distribution via the discrete inverse-transform
# method: s = iceil(F^{-1}(u)) where u = rand(), which is simply
# s = iceil(log(rand()) / log1p(-p)).
# method: s = ceil(F^{-1}(u)) where u = rand(), which is simply
# s = ceil(log(rand()) / log1p(-p)).
L = 1 / log1p(-p)
i = 0
while true
s = log(rand()) * L # note that rand() < 1, so s > 0
s >= n - i && return S # compare before iceil to avoid overflow
push!(S, A[i += iceil(s)])
s >= n - i && return S # compare before ceil to avoid overflow
push!(S, A[i += ceil(Int,s)])
end
# [This algorithm is similar in spirit to, but much simpler than,
# the one by Vitter for a related problem in "Faster methods for
Expand Down
5 changes: 1 addition & 4 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,7 @@ function empty!(B::BitVector)
end

## Misc functions

for f in (:iround, :itrunc, :ifloor, :iceil, :abs)
@eval ($f)(B::BitArray) = copy(B)
end
abs(B::BitArray) = copy(B)

## Unary operators ##

Expand Down
2 changes: 1 addition & 1 deletion base/char.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
char(x) = convert(Char, x)
char(x::FloatingPoint) = char(iround(x))
char(x::FloatingPoint) = char(round(UInt32,x))

integer(x::Char) = int(x)

Expand Down
12 changes: 5 additions & 7 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,21 +477,19 @@ function ^{T<:Complex}(z::T, p::T)

# apply some corrections to force known zeros
if pim == 0
ip = itrunc(pr)
if ip == pr
if isinteger(pr)
if zi == 0
im = copysign(zero(im), im)
elseif zr == 0
if isodd(ip)
re = copysign(zero(re), re)
else
if isinteger(0.5*pr) # pr is even
im = copysign(zero(im), im)
else
re = copysign(zero(re), re)
end
end
else
dr = pr*2
ip = itrunc(dr)
if ip == dr && zi == 0
if isinteger(dr) && zi == 0
if zr < 0
re = copysign(zero(re), re)
else
Expand Down
2 changes: 1 addition & 1 deletion base/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end
# get array of start indexes for dividing sz into nc chunks
function defaultdist(sz::Int, nc::Int)
if sz >= nc
iround(linspace(1, sz+1, nc+1))
round(Int,linspace(1, sz+1, nc+1))
else
[[1:(sz+1)], zeros(Int, nc-sz)]
end
Expand Down
2 changes: 1 addition & 1 deletion base/dates/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Base.colon{T<:DateTime}(start::T, stop::T) = StepRange(start, Day(1), stop)

# Given a start and end date, how many steps/periods are in between
guess(a::DateTime,b::DateTime,c) = ifloor(Int64,(int128(b) - int128(a))/toms(c))
guess(a::DateTime,b::DateTime,c) = floor(Int64,(int128(b) - int128(a))/toms(c))
guess(a::Date,b::Date,c) = int64(div(int64(b - a),days(c)))
function len(a,b,c)
lo, hi, st = min(a,b), max(a,b), abs(c)
Expand Down
9 changes: 9 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,12 @@ const Uint128 = UInt128

@deprecate rand!(r::Range, A::AbstractArray) rand!(A, r)
@deprecate rand!(mt::MersenneTwister, r::Range, A::AbstractArray) rand!(mt, A, r)

@deprecate itrunc(x) trunc(Integer,x)
@deprecate itrunc{T<:Integer}(::Type{T},x::Real) trunc(T,x)
@deprecate iceil(x) ceil(Integer,x)
@deprecate iceil{T}(::Type{T},x) ceil(T,x)
@deprecate ifloor(x) floor(Integer,x)
@deprecate ifloor{T}(::Type{T},x) floor(T,x)
@deprecate iround(x) round(Integer,x)
@deprecate iround{T}(::Type{T},x) round(T,x)
4 changes: 0 additions & 4 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,6 @@ export
gcdx,
hex2num,
hypot,
iceil,
ifloor,
imag,
int,
int128,
Expand All @@ -373,7 +371,6 @@ export
inv,
invdigamma,
invmod,
iround,
isapprox,
iseltype,
iseven,
Expand All @@ -387,7 +384,6 @@ export
isqrt,
isreal,
issubnormal,
itrunc,
lcm,
ldexp,
leading_ones,
Expand Down
Loading