From 2dbb37dc54ef42f5b949d357ffafb3ad84a68658 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Sun, 17 Nov 2013 18:13:41 -0500 Subject: [PATCH] =?UTF-8?q?do=20NOT=20add=20a=20methods=20for=20mod(x,y::M?= =?UTF-8?q?athConst{:=CF=80})?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/constants.jl | 10 ---------- test/math-modpi.jl | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/base/constants.jl b/base/constants.jl index 1628742f75798..0a906c0567dcc 100644 --- a/base/constants.jl +++ b/base/constants.jl @@ -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 diff --git a/test/math-modpi.jl b/test/math-modpi.jl index 3e0adf31495c0..51cfefc690592 100644 --- a/test/math-modpi.jl +++ b/test/math-modpi.jl @@ -198,12 +198,11 @@ 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 @@ -211,7 +210,9 @@ testModPi() @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 @@ -219,13 +220,14 @@ testModPi() @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) +