Skip to content

Commit

Permalink
do NOT add a methods for mod(x,y::MathConst{:π})
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianlischka committed Nov 17, 2013
1 parent 86a6ab4 commit 2dbb37d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
10 changes: 0 additions & 10 deletions base/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,3 @@ end
^(::MathConst{:e}, x::AbstractMatrix) = expm(x)

log(::MathConst{:e}) = 1 # use 1 to correctly promote expressions like log(x)/log(e)

mod(x::Float64, y::MathConst{:π}) = modpi(x)
mod(x::Float32, y::MathConst{:π}) = modpi(x)
mod(x::Int32, y::MathConst{:π}) = modpi(x)
mod(x::Int64, y::MathConst{:π}) = modpi(x)
# Note: with these 3 lines above, we have:
# mod(5706674932067741.0,pi) == 4.237546464512562e-16 # correct, modpi called
# mod(5706674932067741,pi) == 4.237546464512562e-16 # correct, modpi called
# mod(5706674932067741,pi*1) == 0.2224559947753093 # second arg Float64: original "mod" called
# mod(5706674932067741.0,pi*1)== 0.2224559947753093 # second arg Float64: original "mod" called
18 changes: 10 additions & 8 deletions test/math-modpi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,34 +198,36 @@ function testModPi()
end


println("hello ", mod(355.0,2pi) - mod2pi(355.0))
println("hello ", mod(355.0,pi) - modpi(355.0))
println("hello ", mod(355.0,pi/2) - modpio2(355.0))

testModPi()
# 2pi
@test_approx_eq mod2pi(10) mod(10,2pi)
@test_approx_eq mod2pi(-10) mod(-10,2pi)
@test_approx_eq mod2pi(355) 3.1416227979431572
@test_approx_eq mod2pi(int32(355)) 3.1416227979431572
@test_approx_eq mod2pi(355.0) 3.1416227979431572
@test_approx_eq mod2pi(355.0f0) 3.1416228f0
@test mod2pi(2^60) == mod2pi(2.0^60)
@test_throws mod2pi(2^60-1)

# pi - also test that mod(x,pi) == modpi(x)
# pi
@test_approx_eq modpi(10) mod(10,pi)
@test_approx_eq modpi(-10) mod(-10,pi)
@test_approx_eq modpi(355) 3.014435336405372e-5
@test_approx_eq modpi(int32(355)) 3.014435336405372e-5
@test_approx_eq modpi(355.0) 3.014435336405372e-5
@test_approx_eq modpi(355.0f0) 3.0144354f-5
@test modpi(2^60) == modpi(2.0^60)
@test_throws modpi(2^60-1)

@test modpi(355) == mod(355,pi)
@test modpi(int32(355)) == mod(int32(355),pi)
@test modpi(355.0) == mod(355.0,pi)
@test modpi(355.0f0) == mod(355.0f0,pi)

# pi/2
@test_approx_eq modpio2(10) mod(10,pi/2)
@test_approx_eq modpio2(-10) mod(-10,pi/2)
@test_approx_eq modpio2(355) 3.014435336405372e-5
@test_approx_eq modpio2(int32(355)) 3.014435336405372e-5
@test_approx_eq modpio2(355.0) 3.014435336405372e-5
@test_approx_eq modpio2(355.0f0) 3.0144354f-5
@test modpio2(2^60) == modpio2(2.0^60)
@test_throws modpio2(2^60-1)

0 comments on commit 2dbb37d

Please sign in to comment.