Skip to content

Commit 5fa05dc

Browse files
fredrikekreKristofferC
authored andcommitted
Rename num/den to numerator/denominator (#19246)
* rename num/den -> numerator/denominator * added news entry [ci skip] * grammar [ci skip]
1 parent c263a6e commit 5fa05dc

File tree

12 files changed

+62
-58
lines changed

12 files changed

+62
-58
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Deprecated or removed
6666

6767
* `is` has been deprecated in favor of `===` (which used to be an alias for `is`) ([#17758]).
6868

69+
* `num` and `den` have been deprecated in favor of `numerator` and `denominator` respectively ([#19233]).
70+
6971
Julia v0.5.0 Release Notes
7072
==========================
7173

@@ -693,3 +695,4 @@ Language tooling improvements
693695
[#18473]: https://github.com/JuliaLang/julia/issues/18473
694696
[#18839]: https://github.com/JuliaLang/julia/issues/18839
695697
[#19018]: https://github.com/JuliaLang/julia/issues/19018
698+
[#19233]: https://github.com/JuliaLang/julia/issues/19233

base/deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,4 +1098,8 @@ eval(Base.LinAlg, quote
10981098
end
10991099
end)
11001100

1101+
# #19246
1102+
@deprecate den denominator
1103+
@deprecate num numerator
1104+
11011105
# End deprecations scheduled for 0.6

base/docs/helpdb/Base.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -999,13 +999,6 @@ In-place version of [`reverse`](:func:`reverse`).
999999
"""
10001000
reverse!
10011001

1002-
"""
1003-
num(x)
1004-
1005-
Numerator of the rational representation of `x`.
1006-
"""
1007-
num
1008-
10091002
"""
10101003
.<(x, y)
10111004
@@ -2617,13 +2610,6 @@ The process was stopped by a terminal interrupt (CTRL+C).
26172610
"""
26182611
InterruptException
26192612

2620-
"""
2621-
den(x)
2622-
2623-
Denominator of the rational representation of `x`.
2624-
"""
2625-
den
2626-
26272613
"""
26282614
issubnormal(f) -> Bool
26292615

base/exports.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export
332332
csch,
333333
dawson,
334334
deg2rad,
335-
den,
335+
denominator,
336336
digamma,
337337
div,
338338
divrem,
@@ -400,7 +400,7 @@ export
400400
nextpow,
401401
nextpow2,
402402
nextprod,
403-
num,
403+
numerator,
404404
num2hex,
405405
one,
406406
powermod,

base/hashing2.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Special values:
9494
=#
9595

9696
decompose(x::Integer) = x, 0, 1
97-
decompose(x::Rational) = num(x), 0, den(x)
97+
decompose(x::Rational) = numerator(x), 0, denominator(x)
9898

9999
function decompose(x::Float16)::NTuple{3,Int}
100100
isnan(x) && return 0, 0, 0
@@ -144,7 +144,7 @@ end
144144
## streamlined hashing for smallish rational types ##
145145

146146
function hash{T<:BitInteger64}(x::Rational{T}, h::UInt)
147-
num, den = Base.num(x), Base.den(x)
147+
num, den = Base.numerator(x), Base.denominator(x)
148148
den == 1 && return hash(num, h)
149149
den == 0 && return hash(ifelse(num > 0, Inf, -Inf), h)
150150
if isodd(den)

base/mpfr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ convert(::Type{BigFloat}, x::Union{Bool,Int8,Int16,Int32}) = BigFloat(convert(Cl
107107
convert(::Type{BigFloat}, x::Union{UInt8,UInt16,UInt32}) = BigFloat(convert(Culong,x))
108108

109109
convert(::Type{BigFloat}, x::Union{Float16,Float32}) = BigFloat(Float64(x))
110-
convert(::Type{BigFloat}, x::Rational) = BigFloat(num(x)) / BigFloat(den(x))
110+
convert(::Type{BigFloat}, x::Rational) = BigFloat(numerator(x)) / BigFloat(denominator(x))
111111

112112
function tryparse(::Type{BigFloat}, s::AbstractString, base::Int=0)
113113
z = BigFloat()

base/rational.jl

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ end
4444
.//(y::Number, X::AbstractArray) = reshape([ y // x for x in X ], size(X))
4545

4646
function show(io::IO, x::Rational)
47-
show(io, num(x))
47+
show(io, numerator(x))
4848
print(io, "//")
49-
show(io, den(x))
49+
show(io, denominator(x))
5050
end
5151

5252
function read{T<:Integer}(s::IO, ::Type{Rational{T}})
@@ -55,7 +55,7 @@ function read{T<:Integer}(s::IO, ::Type{Rational{T}})
5555
r//i
5656
end
5757
function write(s::IO, z::Rational)
58-
write(s,num(z),den(z))
58+
write(s,numerator(z),denominator(z))
5959
end
6060

6161
convert{T<:Integer}(::Type{Rational{T}}, x::Rational) = Rational{T}(convert(T,x.num),convert(T,x.den))
@@ -104,7 +104,7 @@ julia> rationalize(5.6)
104104
julia> a = rationalize(BigInt, 10.3)
105105
103//10
106106
107-
julia> typeof(num(a))
107+
julia> typeof(numerator(a))
108108
BigInt
109109
```
110110
"""
@@ -170,10 +170,21 @@ end
170170
rationalize{T<:Integer}(::Type{T}, x::AbstractFloat; tol::Real=eps(x)) = rationalize(T, x, tol)::Rational{T}
171171
rationalize(x::AbstractFloat; kvs...) = rationalize(Int, x; kvs...)
172172

173-
num(x::Integer) = x
174-
den(x::Integer) = one(x)
175-
num(x::Rational) = x.num
176-
den(x::Rational) = x.den
173+
"""
174+
numerator(x)
175+
176+
Numerator of the rational representation of `x`.
177+
"""
178+
numerator(x::Integer) = x
179+
numerator(x::Rational) = x.num
180+
181+
"""
182+
denominator(x)
183+
184+
Denominator of the rational representation of `x`.
185+
"""
186+
denominator(x::Integer) = one(x)
187+
denominator(x::Rational) = x.den
177188

178189
sign(x::Rational) = oftype(x, sign(x.num))
179190
signbit(x::Rational) = signbit(x.num)
@@ -313,51 +324,51 @@ ceil{ T}(::Type{T}, x::Rational) = convert(T,cld(x.num,x.den))
313324

314325

315326
function round{T, Tr}(::Type{T}, x::Rational{Tr}, ::RoundingMode{:Nearest})
316-
if den(x) == zero(Tr) && T <: Integer
327+
if denominator(x) == zero(Tr) && T <: Integer
317328
throw(DivideError())
318-
elseif den(x) == zero(Tr)
319-
return convert(T, copysign(one(Tr)//zero(Tr), num(x)))
329+
elseif denominator(x) == zero(Tr)
330+
return convert(T, copysign(one(Tr)//zero(Tr), numerator(x)))
320331
end
321-
q,r = divrem(num(x), den(x))
332+
q,r = divrem(numerator(x), denominator(x))
322333
s = q
323-
if abs(r) >= abs((den(x)-copysign(Tr(4), num(x))+one(Tr)+iseven(q))>>1 + copysign(Tr(2), num(x)))
324-
s += copysign(one(Tr),num(x))
334+
if abs(r) >= abs((denominator(x)-copysign(Tr(4), numerator(x))+one(Tr)+iseven(q))>>1 + copysign(Tr(2), numerator(x)))
335+
s += copysign(one(Tr),numerator(x))
325336
end
326337
convert(T, s)
327338
end
328339

329340
round{T}(::Type{T}, x::Rational) = round(T, x, RoundNearest)
330341

331342
function round{T, Tr}(::Type{T}, x::Rational{Tr}, ::RoundingMode{:NearestTiesAway})
332-
if den(x) == zero(Tr) && T <: Integer
343+
if denominator(x) == zero(Tr) && T <: Integer
333344
throw(DivideError())
334-
elseif den(x) == zero(Tr)
335-
return convert(T, copysign(one(Tr)//zero(Tr), num(x)))
345+
elseif denominator(x) == zero(Tr)
346+
return convert(T, copysign(one(Tr)//zero(Tr), numerator(x)))
336347
end
337-
q,r = divrem(num(x), den(x))
348+
q,r = divrem(numerator(x), denominator(x))
338349
s = q
339-
if abs(r) >= abs((den(x)-copysign(Tr(4), num(x))+one(Tr))>>1 + copysign(Tr(2), num(x)))
340-
s += copysign(one(Tr),num(x))
350+
if abs(r) >= abs((denominator(x)-copysign(Tr(4), numerator(x))+one(Tr))>>1 + copysign(Tr(2), numerator(x)))
351+
s += copysign(one(Tr),numerator(x))
341352
end
342353
convert(T, s)
343354
end
344355

345356
function round{T, Tr}(::Type{T}, x::Rational{Tr}, ::RoundingMode{:NearestTiesUp})
346-
if den(x) == zero(Tr) && T <: Integer
357+
if denominator(x) == zero(Tr) && T <: Integer
347358
throw(DivideError())
348-
elseif den(x) == zero(Tr)
349-
return convert(T, copysign(one(Tr)//zero(Tr), num(x)))
359+
elseif denominator(x) == zero(Tr)
360+
return convert(T, copysign(one(Tr)//zero(Tr), numerator(x)))
350361
end
351-
q,r = divrem(num(x), den(x))
362+
q,r = divrem(numerator(x), denominator(x))
352363
s = q
353-
if abs(r) >= abs((den(x)-copysign(Tr(4), num(x))+one(Tr)+(num(x)<0))>>1 + copysign(Tr(2), num(x)))
354-
s += copysign(one(Tr),num(x))
364+
if abs(r) >= abs((denominator(x)-copysign(Tr(4), numerator(x))+one(Tr)+(numerator(x)<0))>>1 + copysign(Tr(2), numerator(x)))
365+
s += copysign(one(Tr),numerator(x))
355366
end
356367
convert(T, s)
357368
end
358369

359370
function round{T}(::Type{T}, x::Rational{Bool})
360-
if den(x) == false && issubtype(T, Union{Integer, Bool})
371+
if denominator(x) == false && issubtype(T, Union{Integer, Bool})
361372
throw(DivideError())
362373
end
363374
convert(T, x)

base/sysimg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ include("mpfr.jl")
247247
importall .MPFR
248248
big(n::Integer) = convert(BigInt,n)
249249
big(x::AbstractFloat) = convert(BigFloat,x)
250-
big(q::Rational) = big(num(q))//big(den(q))
250+
big(q::Rational) = big(numerator(q))//big(denominator(q))
251251

252252
include("combinatorics.jl")
253253

doc/manual/complex-and-rational-numbers.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ are reduced to lowest terms such that the denominator is non-negative:
229229
This normalized form for a ratio of integers is unique, so equality of
230230
rational values can be tested by checking for equality of the numerator
231231
and denominator. The standardized numerator and denominator of a
232-
rational value can be extracted using the :func:`num` and :func:`den` functions:
232+
rational value can be extracted using the :func:`numerator` and :func:`denominator` functions:
233233

234234
.. doctest::
235235

236-
julia> num(2//3)
236+
julia> numerator(2//3)
237237
2
238238

239-
julia> den(2//3)
239+
julia> denominator(2//3)
240240
3
241241

242242
Direct comparison of the numerator and denominator is generally not

doc/stdlib/math.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ Mathematical Operators
324324
julia> typeof(num(a))
325325
BigInt
326326

327-
.. function:: num(x)
327+
.. function:: numerator(x)
328328

329329
.. Docstring generated from Julia source
330330
331331
Numerator of the rational representation of ``x``\ .
332332

333-
.. function:: den(x)
333+
.. function:: denominator(x)
334334

335335
.. Docstring generated from Julia source
336336

0 commit comments

Comments
 (0)