From 4d83f892e11008a165d55ca05833e971c4937f38 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Wed, 13 Nov 2013 01:04:33 -0500 Subject: [PATCH 01/11] initial revision --- base/constants.jl | 26 +++++++++ base/exports.jl | 5 ++ base/math.jl | 131 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) diff --git a/base/constants.jl b/base/constants.jl index 0a906c0567dcc..92f20b471cec9 100644 --- a/base/constants.jl +++ b/base/constants.jl @@ -72,6 +72,24 @@ const eu = e const eulergamma = γ const golden = φ +# multiples of pi FIX FIX FIX - already defined somewhere? Naming? +const pi1o2_bf = pi * BigFloat(1/2) +const pi1o2_h = convert(Float64, pi1o2_bf) +const pi1o2_l = convert(Float64, pi1o2_bf - pi1o2_h) + +const pi2o2_bf = pi * BigFloat(1) +const pi2o2_h = convert(Float64, pi2o2_bf) +const pi2o2_l = convert(Float64, pi2o2_bf - pi2o2_h) + +const pi3o2_bf = pi * BigFloat(3/2) +const pi3o2_h = convert(Float64, pi3o2_bf) +const pi3o2_l = convert(Float64, pi3o2_bf - pi3o2_h) + +const pi4o2_bf = pi * BigFloat(2) +const pi4o2_h = convert(Float64, pi4o2_bf) +const pi4o2_l = convert(Float64, pi4o2_bf - pi4o2_h) + + # special behaviors # use exp for e^x or e.^x, as in @@ -87,3 +105,11 @@ 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) +# Note: with this line above, we have: +# mod(5706674932067741.0,pi) == 4.237546464512562e-16 # correct, modpi called +# mod(5706674932067741,pi) == 0.2224559947753093 # first arg int: original "mod" 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/base/exports.jl b/base/exports.jl index e029518b47f44..600c60f7f20d0 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -180,6 +180,8 @@ export # Mathematical constants im, π, pi, + pi1o2_bf, pi1o2_h, pi1o2_l, pi2o2_bf, pi2o2_h, pi2o2_l, + pi3o2_bf, pi3o2_h, pi3o2_l, pi4o2_bf, pi4o2_h, pi4o2_l, e, eu, γ, eulergamma, catalan, @@ -381,7 +383,10 @@ export maxintfloat, mod, mod1, + mod2pi, modf, + modpi, + modpio2, nan, nextfloat, nextpow, diff --git a/base/math.jl b/base/math.jl index a92550213d104..a3b7de165ab02 100644 --- a/base/math.jl +++ b/base/math.jl @@ -12,6 +12,7 @@ export sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, ceil, floor, trunc, round, significand, lgamma, hypot, gamma, lfact, max, min, ldexp, frexp, clamp, modf, ^, + mod2pi, modpi, modpio2, airy, airyai, airyprime, airyaiprime, airybi, airybiprime, besselj0, besselj1, besselj, bessely0, bessely1, bessely, hankelh1, hankelh2, besseli, besselk, besselh, @@ -1337,4 +1338,134 @@ end erfcinv(x::Integer) = erfcinv(float(x)) @vectorize_1arg Real erfcinv + +function add22Cond(xh::Float64, xl::Float64, yh::Float64, yl::Float64) + # This algorithm, due to Dekker [1], computes the sum of + # two double-double numbers as a double-double, with a relative error smaller than 2^−103 + # [1] http://gdz.sub.uni-goettingen.de/dms/load/img/?PPN=PPN362160546_0018&DMDID=DMDLOG_0023&LOGID=LOG_0023&PHYSID=PHYS_0232 + # [2] http://ftp.nluug.nl/pub/os/BSD/FreeBSD/distfiles/crlibm/crlibm-1.0beta3.pdf + r = xh+yh + s = (abs(xh) > abs(yh)) ? (xh-r+yh+yl+xl) : (yh-r+xh+xl+yl) + zh = r+s + zl = r-zh+s + return (zh,zl) +end + +function add22Cond_h(xh::Float64, xl::Float64, yh::Float64, yl::Float64) + # as above, but only compute and return high double + r = xh+yh + s = (abs(xh) > abs(yh)) ? (xh-r+yh+yl+xl) : (yh-r+xh+xl+yl) + zh = r+s + return zh +end + +function ieee754_rem_pio2(x::Float64) + # rem_pio2 essentially computes x mod pi/2 (ie within a quarter circle) + # and returns the result as + # y between + and - pi/4 (for maximal accuracy (as the sign bit is exploited)), and + # n, where n specifies the integer part of the division, or, at any rate, + # in which quadrant we are. + # The invariant fulfilled by the returned values seems to be + # x = y + n*pi/2 (where y = y1+y2 is a double-double and y2 is the "tail" of y). + # Note: for very large x (thus n), the invariant might hold only modulo 2pi + # (in other words, n might be off by a multiple of 4, or a multiple of 100) + + # this is just wrapping up + # https://github.com/JuliaLang/openlibm/blob/master/src/e_rem_pio2.c?source=c + + y = [0.0,0.0] + n = ccall((:__ieee754_rem_pio2,Base.libm_name), Cint, (Float64,Ptr{Float64}),x,y) + # FIX FIX FIX: or :libm ? + # FIX FIX FIX: Int32 or Cint? + # FIX FIX FIX: - make this a macro instead? + return (n,y) +end + + +function mod2pi(x::Float64) # or modtau(x) +# with r = mod2pi(x) +# a) 0 <= r < 2π (note: boundary open or closed - a bit fuzzy, due to rem_pio2 implementation) +# b) r-x = k*2π with k integer + +# note: mod(n,4) is 0,1,2,3; while mod(n-1,4)+1 is 1,2,3,4. +# We use the latter to push negative y in quadrant 0 into the positive (one revolution, + 4*pi/2) + + if x < pi4o2_h + if 0.0 <= x return x end + if x > -pi4o2_h + return add22Cond_h(x,0.0,pi4o2_h,pi4o2_l) + end + end + + (n,y) = ieee754_rem_pio2(x) + + if iseven(n) + if n & 2 == 2 # add pi + return add22Cond_h(y[1],y[2],pi2o2_h,pi2o2_l) + else # add 0 or 2pi + if y[1] > 0.0 + return y[1] + else # else add 2pi + return add22Cond_h(y[1],y[2],pi4o2_h,pi4o2_l) + end + end + else # add pi/2 or 3pi/2 + if n & 2 == 2 # add 3pi/2 + return add22Cond_h(y[1],y[2],pi3o2_h,pi3o2_l) + else # add pi/2 + return add22Cond_h(y[1],y[2],pi1o2_h,pi1o2_l) + end + end +end + +function modpi(x::Float64) +# with r = modpi(x) +# a) 0 <= r < π (note: boundary open or closed - a bit fuzzy, due to rem_pio2 implementation) +# b) r-x = k*π with k integer + if x < pi2o2_h + if 0.0 <= x return x end + if x > -pi2o2_h + return add22Cond_h(x,0.0,pi2o2_h,pi2o2_l) + end + end + (n,y) = ieee754_rem_pio2(x) + if iseven(n) + if y[1] > 0.0 + return y[1] + else # else add pi + return add22Cond_h(y[1],y[2],pi2o2_h,pi2o2_l) + end + else # add pi/2 + return add22Cond_h(y[1],y[2],pi1o2_h,pi1o2_l) + end +end + + +function modpio2(x::Float64) +# with r = modpio2(x) +# a) 0 <= r < π/2 (note: boundary open or closed - a bit fuzzy, due to rem_pio2 implementation) +# b) r-x = k*π/2 with k integer + +# Note: we explicitly test for 0 <= values < pi/2, because +# ieee754_rem_pio2 behaves weirdly for arguments that are already +# within -pi/4, pi/4 e.g. +# ieee754_rem_pio2(0.19633954084936206) returns +# (1,[-1.3744567859455346,-6.12323399538461e-17]) +# which does not add up to 0.19633954084936206 + if x < pi1o2_h + if x >= 0.0 return x end + if x > -pi1o2_h + zh = add22Cond_h(x,0.0,pi1o2_h,pi1o2_l) + return zh + end + end + (n,y) = ieee754_rem_pio2(x) + if y[1] > 0.0 + return y[1] + else + zh = add22Cond_h(y[1],y[2],pi1o2_h,pi1o2_l) + return zh + end +end + end # module From 7895ac8ebfe55a9f49a75fdfda93139024dbf240 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Thu, 14 Nov 2013 22:50:12 -0500 Subject: [PATCH 02/11] include modpi etc. in the documentation. Don't export pi-related constants. for modpi(Int64), we check that the argument converts to a float64 losslessly, and throw an error otherwise. --- base/constants.jl | 27 +++++--------------------- base/exports.jl | 2 -- base/math.jl | 23 ++++++++++++++++++---- doc/manual/mathematical-operations.rst | 3 +++ 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/base/constants.jl b/base/constants.jl index 92f20b471cec9..9d80f2431ad35 100644 --- a/base/constants.jl +++ b/base/constants.jl @@ -72,24 +72,6 @@ const eu = e const eulergamma = γ const golden = φ -# multiples of pi FIX FIX FIX - already defined somewhere? Naming? -const pi1o2_bf = pi * BigFloat(1/2) -const pi1o2_h = convert(Float64, pi1o2_bf) -const pi1o2_l = convert(Float64, pi1o2_bf - pi1o2_h) - -const pi2o2_bf = pi * BigFloat(1) -const pi2o2_h = convert(Float64, pi2o2_bf) -const pi2o2_l = convert(Float64, pi2o2_bf - pi2o2_h) - -const pi3o2_bf = pi * BigFloat(3/2) -const pi3o2_h = convert(Float64, pi3o2_bf) -const pi3o2_l = convert(Float64, pi3o2_bf - pi3o2_h) - -const pi4o2_bf = pi * BigFloat(2) -const pi4o2_h = convert(Float64, pi4o2_bf) -const pi4o2_l = convert(Float64, pi4o2_bf - pi4o2_h) - - # special behaviors # use exp for e^x or e.^x, as in @@ -107,9 +89,10 @@ end log(::MathConst{:e}) = 1 # use 1 to correctly promote expressions like log(x)/log(e) mod(x::Float64, y::MathConst{:π}) = modpi(x) -# Note: with this line above, we have: +mod(x::Int32, y::MathConst{:π}) = modpi(float64(x)) +mod(x::Int64, y::MathConst{:π}) = if int(float(x))==x modpi(float64(x)) else error("Integer arguments to mod(_,pi) must be 'small enough', namely < 2^53") end +# Note: with these 3 lines above, we have: # mod(5706674932067741.0,pi) == 4.237546464512562e-16 # correct, modpi called -# mod(5706674932067741,pi) == 0.2224559947753093 # first arg int: original "mod" 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 - +# mod(5706674932067741.0,pi*1)== 0.2224559947753093 # second arg Float64: original "mod" called diff --git a/base/exports.jl b/base/exports.jl index 600c60f7f20d0..bb3d933994c83 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -180,8 +180,6 @@ export # Mathematical constants im, π, pi, - pi1o2_bf, pi1o2_h, pi1o2_l, pi2o2_bf, pi2o2_h, pi2o2_l, - pi3o2_bf, pi3o2_h, pi3o2_l, pi4o2_bf, pi4o2_h, pi4o2_l, e, eu, γ, eulergamma, catalan, diff --git a/base/math.jl b/base/math.jl index a3b7de165ab02..ad74b952bb42d 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1374,14 +1374,29 @@ function ieee754_rem_pio2(x::Float64) # https://github.com/JuliaLang/openlibm/blob/master/src/e_rem_pio2.c?source=c y = [0.0,0.0] - n = ccall((:__ieee754_rem_pio2,Base.libm_name), Cint, (Float64,Ptr{Float64}),x,y) - # FIX FIX FIX: or :libm ? - # FIX FIX FIX: Int32 or Cint? - # FIX FIX FIX: - make this a macro instead? + n = ccall(:__ieee754_rem_pio2, Cint, (Float64,Ptr{Float64}),x,y) return (n,y) end +# multiples of pi FIX FIX FIX - already defined somewhere? Naming? +const pi1o2_bf = pi * BigFloat(1/2) +const pi1o2_h = convert(Float64, pi1o2_bf) +const pi1o2_l = convert(Float64, pi1o2_bf - pi1o2_h) + +const pi2o2_bf = pi * BigFloat(1) +const pi2o2_h = convert(Float64, pi2o2_bf) +const pi2o2_l = convert(Float64, pi2o2_bf - pi2o2_h) + +const pi3o2_bf = pi * BigFloat(3/2) +const pi3o2_h = convert(Float64, pi3o2_bf) +const pi3o2_l = convert(Float64, pi3o2_bf - pi3o2_h) + +const pi4o2_bf = pi * BigFloat(2) +const pi4o2_h = convert(Float64, pi4o2_bf) +const pi4o2_l = convert(Float64, pi4o2_bf - pi4o2_h) + + function mod2pi(x::Float64) # or modtau(x) # with r = mod2pi(x) # a) 0 <= r < 2π (note: boundary open or closed - a bit fuzzy, due to rem_pio2 implementation) diff --git a/doc/manual/mathematical-operations.rst b/doc/manual/mathematical-operations.rst index b2d4c55fb11ae..7d6e9df38b851 100644 --- a/doc/manual/mathematical-operations.rst +++ b/doc/manual/mathematical-operations.rst @@ -314,6 +314,9 @@ Function Description ``fld(x,y)`` floored division; quotient rounded towards ``-Inf`` ``rem(x,y)`` remainder; satisfies ``x == div(x,y)*y + rem(x,y)``; sign matches ``x`` ``mod(x,y)`` modulus; satisfies ``x == fld(x,y)*y + mod(x,y)``; sign matches ``y`` +``mod2pi(x)`` modulus with respect to 2pi; ``0 <= mod2pi(x) < 2pi`` +``modpi(x)`` modulus with respect to pi; ``0 <= modpi(x) < pi`` +``modpio2(x)`` modulus with respect to pi/2; ``0 <= modpio2(x) < pi/2`` ``gcd(x,y...)`` greatest common divisor of ``x``, ``y``,...; sign matches ``x`` ``lcm(x,y...)`` least common multiple of ``x``, ``y``,...; sign matches ``x`` =============== ======================================================================= From 92836dd8708e59d46fde00f2ce5906497898f6bd Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Fri, 15 Nov 2013 01:11:17 -0500 Subject: [PATCH 03/11] hardcode pi-related constants. Extend mod2pi, modpi, modpio2 to Ints. --- base/constants.jl | 4 ++-- base/math.jl | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/base/constants.jl b/base/constants.jl index 9d80f2431ad35..e57b53654bb7f 100644 --- a/base/constants.jl +++ b/base/constants.jl @@ -89,8 +89,8 @@ end log(::MathConst{:e}) = 1 # use 1 to correctly promote expressions like log(x)/log(e) mod(x::Float64, y::MathConst{:π}) = modpi(x) -mod(x::Int32, y::MathConst{:π}) = modpi(float64(x)) -mod(x::Int64, y::MathConst{:π}) = if int(float(x))==x modpi(float64(x)) else error("Integer arguments to mod(_,pi) must be 'small enough', namely < 2^53") end +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 diff --git a/base/math.jl b/base/math.jl index ad74b952bb42d..f6476f349bf60 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1380,21 +1380,17 @@ end # multiples of pi FIX FIX FIX - already defined somewhere? Naming? -const pi1o2_bf = pi * BigFloat(1/2) -const pi1o2_h = convert(Float64, pi1o2_bf) -const pi1o2_l = convert(Float64, pi1o2_bf - pi1o2_h) +const pi1o2_h = 1.5707963267948966 # convert(Float64, pi * BigFloat(1/2)) +const pi1o2_l = 6.123233995736766e-17 # convert(Float64, pi * BigFloat(1/2) - pi1o2_h) -const pi2o2_bf = pi * BigFloat(1) -const pi2o2_h = convert(Float64, pi2o2_bf) -const pi2o2_l = convert(Float64, pi2o2_bf - pi2o2_h) +const pi2o2_h = 3.141592653589793 # convert(Float64, pi * BigFloat(1)) +const pi2o2_l = 1.2246467991473532e-16 # convert(Float64, pi * BigFloat(1) - pi2o2_h) -const pi3o2_bf = pi * BigFloat(3/2) -const pi3o2_h = convert(Float64, pi3o2_bf) -const pi3o2_l = convert(Float64, pi3o2_bf - pi3o2_h) +const pi3o2_h = 4.71238898038469 # convert(Float64, pi * BigFloat(3/2)) +const pi3o2_l = 1.8369701987210297e-16 # convert(Float64, pi * BigFloat(3/2) - pi3o2_h) -const pi4o2_bf = pi * BigFloat(2) -const pi4o2_h = convert(Float64, pi4o2_bf) -const pi4o2_l = convert(Float64, pi4o2_bf - pi4o2_h) +const pi4o2_h = 6.283185307179586 # convert(Float64, pi * BigFloat(2)) +const pi4o2_l = 2.4492935982947064e-16 # convert(Float64, pi * BigFloat(2) - pi4o2_h) function mod2pi(x::Float64) # or modtau(x) @@ -1483,4 +1479,13 @@ function modpio2(x::Float64) end end +mod2pi(x::Int32) = mod2pi(float64(x)) +mod2pi(x::Int64) = if int(float(x))==x mod2pi(float64(x)) else error("Integer argument to mod2pi() is too large.") end + +modpi(x::Int32) = modpi(float64(x)) +modpi(x::Int64) = if int(float(x))==x modpi(float64(x)) else error("Integer argument to modpi() is too large.") end + +modpio2(x::Int32) = modpio2(float64(x)) +modpio2(x::Int64) = if int(float(x))==x modpio2(float64(x)) else error("Integer argument to modpio2() is too large.") end + end # module From e2918a4148f072451d899c0837bae8dd60ef4fd0 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Fri, 15 Nov 2013 01:39:31 -0500 Subject: [PATCH 04/11] made a few constants const across the file --- base/math.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/base/math.jl b/base/math.jl index f6476f349bf60..99fa76d76a2bd 100644 --- a/base/math.jl +++ b/base/math.jl @@ -645,9 +645,9 @@ hankelh2(nu, z) = besselh(nu, 2, z) function angle_restrict_symm(theta) - P1 = 4 * 7.8539812564849853515625e-01 - P2 = 4 * 3.7748947079307981766760e-08 - P3 = 4 * 2.6951514290790594840552e-15 + const P1 = 4 * 7.8539812564849853515625e-01 + const P2 = 4 * 3.7748947079307981766760e-08 + const P3 = 4 * 2.6951514290790594840552e-15 y = 2*floor(theta/(2*pi)) r = ((theta - y*P1) - y*P2) - y*P3 @@ -665,7 +665,7 @@ const clg_coeff = [76.18009172947146, -0.5395239384953e-5] function clgamma_lanczos(z) - sqrt2pi = 2.5066282746310005 + const sqrt2pi = 2.5066282746310005 y = x = z temp = x + 5.5 @@ -686,7 +686,7 @@ function lgamma(z::Complex) if real(z) <= 0.5 a = clgamma_lanczos(1-z) b = log(sinpi(z)) - logpi = 1.14472988584940017 + const logpi = 1.14472988584940017 z = logpi - b - a else z = clgamma_lanczos(z) @@ -1379,7 +1379,7 @@ function ieee754_rem_pio2(x::Float64) end -# multiples of pi FIX FIX FIX - already defined somewhere? Naming? +# multiples of pi/2, as double-double (ie with "tail") const pi1o2_h = 1.5707963267948966 # convert(Float64, pi * BigFloat(1/2)) const pi1o2_l = 6.123233995736766e-17 # convert(Float64, pi * BigFloat(1/2) - pi1o2_h) From e8fd8906ed0b8d6f1d9f2d3495af25ae9dd7bc32 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Sat, 16 Nov 2013 01:08:55 -0500 Subject: [PATCH 05/11] Define modpi etc. for Float32, Int32, Int64. Add tests. --- base/math.jl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/base/math.jl b/base/math.jl index 99fa76d76a2bd..baefc3fee24ab 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1479,13 +1479,28 @@ function modpio2(x::Float64) end end -mod2pi(x::Int32) = mod2pi(float64(x)) -mod2pi(x::Int64) = if int(float(x))==x mod2pi(float64(x)) else error("Integer argument to mod2pi() is too large.") end +mod2pi(x::Float32)= Float32(mod2pi(Float64(x))) +mod2pi(x::Int32) = mod2pi(float64(x)) +function mod2pi(x::Int64) + fx = float64(x) + fx == x || error("Integer argument to mod2pi is too large: $x") + mod2pi(fx) +end -modpi(x::Int32) = modpi(float64(x)) -modpi(x::Int64) = if int(float(x))==x modpi(float64(x)) else error("Integer argument to modpi() is too large.") end +modpi(x::Float32) = Float32(modpi(Float64(x))) +modpi(x::Int32) = modpi(float64(x)) +function modpi(x::Int64) + fx = float64(x) + fx == x || error("Integer argument to modpi is too large: $x") + modpi(fx) +end +modpio2(x::Float32)= Float32(modpi2(Float64(x))) modpio2(x::Int32) = modpio2(float64(x)) -modpio2(x::Int64) = if int(float(x))==x modpio2(float64(x)) else error("Integer argument to modpio2() is too large.") end +function modpio2(x::Int64) + fx = float64(x) + fx == x || error("Integer argument to modpio2 is too large: $x") + modpio2(fx) +end end # module From e4e4f9bb8ce49ccb12163eb24afb860d833f3f85 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Sat, 16 Nov 2013 01:18:56 -0500 Subject: [PATCH 06/11] added math-modpi to runtests.jl, add math-modpi to the repository --- test/math-modpi.jl | 522 +++++++++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 3 +- 2 files changed, 524 insertions(+), 1 deletion(-) create mode 100644 test/math-modpi.jl diff --git a/test/math-modpi.jl b/test/math-modpi.jl new file mode 100644 index 0000000000000..f02fdc76e502a --- /dev/null +++ b/test/math-modpi.jl @@ -0,0 +1,522 @@ + + +# NOTES on range reduction +# [1] compute numbers near pi: http://www.cs.berkeley.edu/~wkahan/testpi/nearpi.c +# [2] range reduction: http://hal-ujm.ccsd.cnrs.fr/docs/00/08/69/04/PDF/RangeReductionIEEETC0305.pdf +# [3] precise addition, see Add22: http://ftp.nluug.nl/pub/os/BSD/FreeBSD/distfiles/crlibm/crlibm-1.0beta3.pdf + +# Examples: +# ΓΓ = 6411027962775774 / 2^47 # see [2] above, section 1.2 +# julia> mod(ΓΓ, pi/2) # "naive" way - easily wrong +# 1.7763568394002505e-15 +# julia> modpio2( ΓΓ ) # using function provided here +# 6.189806365883577e-19 +# Wolfram Alpha: mod(6411027962775774 / 2^47, pi/2) +# 6.189806365883577000150671465609655958633034115366621088... × 10^-19 + + + +#### Correct solutions from WolframAlpha (using the middle formula with the exact repr of the Float64) + +## pi +modpiSolns = [ +"mod(-1.5707963267948966,pi) = mod(-(1+2570638124657944/2^52)*2.0^(0),pi) = 1.57079632679489668046366164900741030340188131343760582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(1.5707963267948966,pi) = mod(+(1+2570638124657944/2^52)*2.0^(0),pi) = 1.5707963267948965579989817342720925807952880859375", +"mod(-3.141592653589793,pi) = mod(-(1+2570638124657944/2^52)*2.0^(1),pi) = 1.22464679914735317722606593227500105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933... × 10^-16", +"mod(3.141592653589793,pi) = mod(+(1+2570638124657944/2^52)*2.0^(1),pi) = 3.141592653589793115997963468544185161590576171875", +"mod(6.283185307179586,pi) = mod(+(1+2570638124657944/2^52)*2.0^(2),pi) = 3.14159265358979299353328355380886743898398294437489417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(-6.283185307179586,pi) = mod(-(1+2570638124657944/2^52)*2.0^(2),pi) = 2.44929359829470635445213186455000211641949889184615632812572417997256069650684234135964296173026564613294187689219101164463450718816256962234900568205403877042211119289245897909860763928857621951331866... × 10^-16", +"mod(45.553093477052,pi) = mod(+(1+1907428335405278/2^52)*2.0^(5),pi) = 1.57079632679489661985030232822810914211365184624851850635077570769057031199307401920751244521036104824992678881404770694068617546629184875584496828620126435569602256217286070452216497527871463097465249799664...", +"mod(3.14159265359,pi) = mod(+(1+2570638124658410/2^52)*2.0^(1),pi) = 2.06823107110214443817242336338901406144179025055407692183593713791001371965174657882932017851913486717693352906155390449417768274640591871518882549715897298061478894440355377051045069618035571189024334... × 10^-13", +"mod(-3.14159265359,pi) = mod(-(1+2570638124658410/2^52)*2.0^(1),pi) = 3.14159265358958641535553316883568564186083049796896164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.9269808169872418,pi) = mod(-(1+4339175044666918/2^52)*2.0^(1),pi) = 2.35620449019234470335066281789739528427110881828146164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.73063127613788,pi) = mod(-(1+3897035185165141/2^52)*2.0^(1),pi) = 2.55255403104170655105593060965009877214418621085958664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.5342817352885176,pi) = mod(-(1+3454895325663363/2^52)*2.0^(1),pi) = 2.74890357189106884285040825146541842946993083976583664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.337932194439156,pi) = mod(-(1+3012755466161586/2^52)*2.0^(1),pi) = 2.94525311274043069055567604321812191734300823234396164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.1415826535897935,pi) = mod(-(1+2570615606659808/2^52)*2.0^(1),pi) = 9.9999999997438875103017539386904715834618751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288... × 10^-6", +"mod(-2.9452331127404316,pi) = mod(-(1+2128475747158031/2^52)*2.0^(1),pi) = 0.19635954084936159159277809350664217834466085445323082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.7488835718910694,pi) = mod(-(1+1686335887656253/2^52)*2.0^(1),pi) = 0.39270908169872388338725573532196183567040548335948082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.5525340310417075,pi) = mod(-(1+1244196028154476/2^52)*2.0^(1),pi) = 0.58905862254808573109252352707466532354348287593760582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.356184490192345,pi) = mod(-(1+802056168652698/2^52)*2.0^(1),pi) = 0.78540816339744802288700116888998498086922750484385582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.1598349493429834,pi) = mod(-(1+359916309150921/2^52)*2.0^(1),pi) = 0.98175770424680987059226896064268846874230489742198082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.9634854084936209,pi) = mod(-(1+4339152526668781/2^52)*2.0^(0),pi) = 1.17810724509617238443135152748931621079438314449229332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.7671358676442588,pi) = mod(-(1+3454872807665226/2^52)*2.0^(0),pi) = 1.37445678594553445418122424427332778339379415523448082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.5707863267948967,pi) = mod(-(1+2570593088661671/2^52)*2.0^(0),pi) = 1.57080632679489652393109696105733935599320516597666832097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.3744367859455346,pi) = mod(-(1+1686313369658116/2^52)*2.0^(0),pi) = 1.76715586764425859368096967784135092859261617671885582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.1780872450961726,pi) = mod(-(1+802033650654561/2^52)*2.0^(0),pi) = 1.96350540849362066343084239462536250119202718746104332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.9817377042468104,pi) = mod(-(1+4339107490672507/2^52)*2.0^(-1),pi) = 2.15985494934298284420301757392502811615460500728526207097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.7853881633974483,pi) = mod(-(1+2570548052665397/2^52)*2.0^(-1),pi) = 2.35620449019234491395289029070903968875401601802744957097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.5890386225480863,pi) = mod(-(1+801988614658287/2^52)*2.0^(-1),pi) = 2.55255403104170698370276300749305126135342702876963707097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.3926890816987242,pi) = mod(-(1+2570457980672850/2^52)*2.0^(-2),pi) = 2.74890357189106905345263572427706283395283803951182457097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.1963395408493621,pi) = mod(-(1+2570277836687755/2^52)*2.0^(-3),pi) = 2.94525311274043115095808405668998791714304075252451988347494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(1.0e-5,pi) = mod(+(1+1399358476216561/2^52)*2.0^(-17),pi) = 0.000010000000000000000818030539140313095458623138256371021270751953125", +"mod(0.19635954084936205,pi) = mod(+(1+2570998412628133/2^52)*2.0^(-3),pi) = 0.1963595408493620519951861069785081781446933746337890625", +"mod(0.3927090816987241,pi) = mod(+(1+2570818268643038/2^52)*2.0^(-2),pi) = 0.39270908169872409398948320813360624015331268310546875", +"mod(0.5890586225480862,pi) = mod(+(1+802168758643381/2^52)*2.0^(-1),pi) = 0.58905862254808616373935592491761781275272369384765625", +"mod(0.7854081633974482,pi) = mod(+(1+2570728196650491/2^52)*2.0^(-1),pi) = 0.78540816339744823348922864170162938535213470458984375", +"mod(0.9817577042468103,pi) = mod(+(1+4339287634657601/2^52)*2.0^(-1),pi) = 0.98175770424681030323910135848564095795154571533203125", +"mod(1.1781072450961723,pi) = mod(+(1+802123722647107/2^52)*2.0^(0),pi) = 1.1781072450961722619666716127539984881877899169921875", +"mod(1.3744567859455343,pi) = mod(+(1+1686403441650662/2^52)*2.0^(0),pi) = 1.374456785945534331716544329538010060787200927734375", +"mod(1.5708063267948964,pi) = mod(+(1+2570683160654217/2^52)*2.0^(0),pi) = 1.5708063267948964014664170463220216333866119384765625", +"mod(1.7671558676442585,pi) = mod(+(1+3454962879657772/2^52)*2.0^(0),pi) = 1.76715586764425847121628976310603320598602294921875", +"mod(1.9635054084936205,pi) = mod(+(1+4339242598661327/2^52)*2.0^(0),pi) = 1.9635054084936205409661624798900447785854339599609375", +"mod(2.159854949342982,pi) = mod(+(1+359961345147192/2^52)*2.0^(1),pi) = 2.159854949342982166626825346611440181732177734375", +"mod(2.3562044901923445,pi) = mod(+(1+802101204648970/2^52)*2.0^(1),pi) = 2.35620449019234445842130298842675983905792236328125", +"mod(2.5525540310417063,pi) = mod(+(1+1244241064150747/2^52)*2.0^(1),pi) = 2.552554031041706306126570780179463326930999755859375", +"mod(2.7489035718910686,pi) = mod(+(1+1686380923652525/2^52)*2.0^(1),pi) = 2.748903571891068597921048421994782984256744384765625", +"mod(2.9452531127404304,pi) = mod(+(1+2128520783154302/2^52)*2.0^(1),pi) = 2.94525311274043044562631621374748647212982177734375", +"mod(3.1416026535897927,pi) = mod(+(1+2570660642656080/2^52)*2.0^(1),pi) = 9.9999999994989581504722833032452583970068748941790250554076921835937137910013719651746578829320178519134867176933529061553904494177682746405918715188825497158972980614788944403553770510450696180355712... × 10^-6", +"mod(3.3379521944391546,pi) = mod(+(1+3012800502157857/2^52)*2.0^(1),pi) = 0.19635954084936134666341826403600673313147439945301917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.534301735288517,pi) = mod(+(1+3454940361659635/2^52)*2.0^(1),pi) = 0.39270908169872363845789590585132639045721902835926917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.7306512761378787,pi) = mod(+(1+3897080221161412/2^52)*2.0^(1),pi) = 0.58905862254808548616316369760402987833029642093739417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.927000816987241,pi) = mod(+(1+4339220080663190/2^52)*2.0^(1),pi) = 0.78540816339744777795764133941934953565604104984364417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(-3.9270008169872415,pi) = mod(-(1+4339220080663191/2^52)*2.0^(1),pi) = 2.35618449019234501641579219379753717908846111320333664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.7306512761378796,pi) = mod(-(1+3897080221161414/2^52)*2.0^(1),pi) = 2.55253403104170686412105998555024066696153850578146164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.5343017352885173,pi) = mod(-(1+3454940361659636/2^52)*2.0^(1),pi) = 2.74888357189106915591553762736556032428728313468771164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.3379521944391555,pi) = mod(-(1+3012800502157859/2^52)*2.0^(1),pi) = 2.94523311274043100362080541911826381216036052726583664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.141602653589793,pi) = mod(-(1+2570660642656081/2^52)*2.0^(1),pi) = 3.14158265358979329541528306093358346948610515617208664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.9452531127404313,pi) = mod(-(1+2128520783154304/2^52)*2.0^(1),pi) = 0.19633954084936190465790746940678407316201314937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.748903571891069,pi) = mod(-(1+1686380923652526/2^52)*2.0^(1),pi) = 0.39268908169872419645238511122210373048775777828135582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.552554031041707,pi) = mod(-(1+1244241064150749/2^52)*2.0^(1),pi) = 0.58903862254808604415765290297480721836083517085948082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.356204490192345,pi) = mod(-(1+802101204648971/2^52)*2.0^(1),pi) = 0.78538816339744833595213054479012687568657979976573082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.159854949342983,pi) = mod(-(1+359961345147194/2^52)*2.0^(1),pi) = 0.98173770424681018365739833654283036355965719234385582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.9635054084936208,pi) = mod(-(1+4339242598661328/2^52)*2.0^(0),pi) = 1.17808724509617247545187597835815002088540182125010582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.7671558676442587,pi) = mod(-(1+3454962879657773/2^52)*2.0^(0),pi) = 1.37443678594553454520174869514216159348481283199229332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.5708063267948966,pi) = mod(-(1+2570683160654218/2^52)*2.0^(0),pi) = 1.57078632679489661495162141192617316608422384273448082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.3744567859455346,pi) = mod(-(1+1686403441650663/2^52)*2.0^(0),pi) = 1.76713586764425868470149412871018473868363485347666832097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.1781072450961725,pi) = mod(-(1+802123722647108/2^52)*2.0^(0),pi) = 1.96348540849362075445136684549419631128304586421885582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.9817577042468104,pi) = mod(-(1+4339287634657602/2^52)*2.0^(-1),pi) = 2.15983494934298282420123956227820788388245687496104332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.7854081633974483,pi) = mod(-(1+2570728196650492/2^52)*2.0^(-1),pi) = 2.35618449019234489395111227906221945648186788570323082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.5890586225480863,pi) = mod(-(1+802168758643382/2^52)*2.0^(-1),pi) = 2.55253403104170696370098499584623102908127889644541832097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.39270908169872415,pi) = mod(-(1+2570818268643039/2^52)*2.0^(-2),pi) = 2.74888357189106908896200894388806962286227331172862144597494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-0.19635954084936208,pi) = mod(-(1+2570998412628134/2^52)*2.0^(-3),pi) = 2.94523311274043115871188166067208119546168432247080894597494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.0e-5,pi) = mod(-(1+1399358476216561/2^52)*2.0^(-17),pi) = 3.14158265358979323846182535274036257110171077623684944995367384035469140628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(0.19633954084936206,pi) = mod(+(1+2570277836687754/2^52)*2.0^(-3),pi) = 0.196339540849362059748983710960601456463336944580078125", +"mod(0.39268908169872413,pi) = mod(+(1+2570457980672849/2^52)*2.0^(-2),pi) = 0.392689081698724129498856427744613029062747955322265625", +"mod(0.5890386225480861,pi) = mod(+(1+801988614658286/2^52)*2.0^(-1),pi) = 0.5890386225480861437375779132707975804805755615234375", +"mod(0.7853881633974482,pi) = mod(+(1+2570548052665396/2^52)*2.0^(-1),pi) = 0.785388163397448213487450630054809153079986572265625", +"mod(0.9817377042468103,pi) = mod(+(1+4339107490672506/2^52)*2.0^(-1),pi) = 0.9817377042468102832373233468388207256793975830078125", +"mod(1.1780872450961724,pi) = mod(+(1+802033650654560/2^52)*2.0^(0),pi) = 1.17808724509617235298719606362283229827880859375", +"mod(1.3744367859455344,pi) = mod(+(1+1686313369658115/2^52)*2.0^(0),pi) = 1.3744367859455344227370687804068438708782196044921875", +"mod(1.5707863267948965,pi) = mod(+(1+2570593088661670/2^52)*2.0^(0),pi) = 1.570786326794896492486941497190855443477630615234375", +"mod(1.7671358676442586,pi) = mod(+(1+3454872807665225/2^52)*2.0^(0),pi) = 1.7671358676442585622368142139748670160770416259765625", +"mod(1.9634854084936206,pi) = mod(+(1+4339152526668780/2^52)*2.0^(0),pi) = 1.96348540849362063198668693075887858867645263671875", +"mod(2.1598349493429825,pi) = mod(+(1+359916309150919/2^52)*2.0^(1),pi) = 2.159834949342982479691954722511582076549530029296875", +"mod(2.3561844901923448,pi) = mod(+(1+802056168652697/2^52)*2.0^(1),pi) = 2.356184490192344771486432364326901733875274658203125", +"mod(2.5525340310417066,pi) = mod(+(1+1244196028154474/2^52)*2.0^(1),pi) = 2.55253403104170661919170015607960522174835205078125", +"mod(2.748883571891069,pi) = mod(+(1+1686335887656252/2^52)*2.0^(1),pi) = 2.7488835718910689109861777978949248790740966796875", +"mod(2.9452331127404308,pi) = mod(+(1+2128475747158029/2^52)*2.0^(1),pi) = 2.945233112740430758691445589647628366947174072265625", +"mod(3.141582653589793,pi) = mod(+(1+2570615606659807/2^52)*2.0^(1),pi) = 3.141582653589793050485923231462948024272918701171875", +"mod(3.337932194439155,pi) = mod(+(1+3012755466161584/2^52)*2.0^(1),pi) = 0.19633954084936165972854763993614862794882669437489417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.534281735288517,pi) = mod(+(1+3454895325663362/2^52)*2.0^(1),pi) = 0.39268908169872395152302528175146828527457132328114417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.730631276137879,pi) = mod(+(1+3897035185165139/2^52)*2.0^(1),pi) = 0.58903862254808579922829307350417177314764871585926917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.9269808169872413,pi) = mod(+(1+4339175044666917/2^52)*2.0^(1),pi) = 0.78538816339744809102277071531949143047339334476551917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(22.0,pi) = mod(+(1+1688849860263936/2^52)*2.0^(4),pi) = 0.00885142487144733076149631704347981061981420437425925317538785384528515599653700960375622260518052412496339440702385347034308773314592437792248414310063217784801128108643035226108248763935731548732624899832...", +"mod(333.0,pi) = mod(+(1+1354598325420032/2^52)*2.0^(8),pi) = 3.13277137307170996142244475565219715929721306561388879763081780767927733994805514405634333907770786187445091610535780205514631599718886566883726214650948266772016921629645528391623731459035973230989373497484...", +"mod(355.0,pi) = mod(+(1+1741626418397184/2^52)*2.0^(8),pi) = 0.00003014435336405372129768941617408571985787061304222983126106921674608965838315503206473634077131801726622399909934887839555912078420781503438688148163372811789639468094711507176015760676809286683801954435...", +"mod(103993.0,pi) = mod(+(1+2642744916836352/2^52)*2.0^(16),pi) = 3.14157352425401364804137006517503018949571128462221990835905001896913552019593641341924635058293272291618832384236767454664957926617754765887823153914653127814591646313301288487020333576664284942659544192789...", +"mod(104348.0,pi) = mod(+(1+2667140331077632/2^52)*2.0^(16),pi) = 0.00001101501758446330002437131170139101839975586015631721536649587806520356811056982327626158158697295130646132818471677795129377741117324218725901249968388881352875511202147883640384875046198736305149704344...", +"mod(208341.0,pi) = mod(+(1+2654942623956992/2^52)*2.0^(17),pi) = 3.14158453927159811134139443648673158051411104048237622557441651484720072376404698324252261216451969586749478517055239132460087304358872090106549055164621516695944521824503436370660718451710483678964693897133...", +"mod(312689.0,pi) = mod(+(1+868356487905280/2^52)*2.0^(18),pi) = 2.90069938933617877542451893008733534139696742672181483841841744952104594855443776404840398960083665315998545480145545832221144931191152739015601741793832268987065511732143745138864461786922231647158597... × 10^-6", +"mod(833719.0,pi) = mod(+(1+2657992050737152/2^52)*2.0^(19),pi) = 3.14159034067037678369894528552459175518479383441722966920409335168209976585594409211805070897249889754080110514146199423551751746648734472412027086368105104360482495955526900658150996180634057523427988214327...", +"mod(1.146408e6,pi) = mod(+(1+420185240502272/2^52)*2.0^(20),pi) = 5.87779972881415077326764018958322965832009550570043987177791732880615683647927779932034371430395306178613634489043881995068386074403922301611569987864477230727508447806913401705828009489526214389300436... × 10^-7", +"mod(4.272943e6,pi) = mod(+(1+84437983297536/2^52)*2.0^(22),pi) = 3.14159210401029542794417726581664863015369133044588137933605488505729840770299503590139050507561318872671964098236546136716350267164556793588717569839101463703651714208061242732171507929036904381292305004458...", +"mod(5.419351e6,pi) = mod(+(1+1315384200265728/2^52)*2.0^(22),pi) = 3.82004750708966112093011647042794877630803261284050974705412148820324696852011356117678675511398777330827176437639516531304810601080841179018325213840634637668871217131295571404954295784087554749162140... × 10^-8", +"mod(8.0143857e7,pi) = mod(+(1+874763572477952/2^52)*2.0^(26),pi) = 3.14159263881694642049673419603295449006652001357044717700741947263430675615757062871728906982575890468500790414041247406248664649838040944906482632404631401392500987850031641113551504622638314153549969887158...", +"mod(1.65707065e8,pi) = mod(+(1+1056606817091584/2^52)*2.0^(27),pi) = 8.65478143496479283480806791601818899147100884047004723119419558177519294537964410073515122454559736833697797859473725690814071454276305173366818717701291531848387749318946794370229795161899094380176246... × 10^-9", +"mod(2.45850922e8,pi) = mod(+(1+3745788417015808/2^52)*2.0^(27),pi) = 3.14159264747172785546152703084102240608470900504145601747746670382850233793276357409693317056091012923060527247739045265722390340652112399182787805771450119093792519698419390432498298992868109315449064267334...", +"mod(4.11557987e8,pi) = mod(+(1+2401197617053696/2^52)*2.0^(28),pi) = 2.53671605196367648236958743790572859713735903697256934271488151342174752084854244595394428579405455430108612460486731570511125630286557038325420725050055641276613287640889128900803008984309962204629913... × 10^-9", +"mod(1.068966896e9,pi) = mod(+(1+4463544628150272/2^52)*2.0^(29),pi) = 3.14159265254515995938887999558019728189616619931617409142260538925826536477625861579401806246879870081871438107956270186695853481674363659755901882422291569193903802251645965714276556794474127284068988676594...", +"mod(2.549491779e9,pi) = mod(+(1+843072155942912/2^52)*2.0^(31),pi) = 4.47449493816149706970976233303722197019495577867890936615779430401846755180508920207307551467187143433646915044596696119497365034532889215443076399478064252395175148483303135651614725663715466720569020... × 10^-10", +"mod(6.167950454e9,pi) = mod(+(1+1963965187883008/2^52)*2.0^(32),pi) = 3.14159265344005894702117940952214974850361059335516524715838726248982422557995212615503590288341380375308866794685653195615192705573836666662479725510906849089516652730680995410937183924797072416812082020708...", +"mod(1.4885392687e10,pi) = mod(+(1+3300633133711360/2^52)*2.0^(33),pi) = 1.47980910933221759456269961916604584979614430234776276979795068989333010234511075289901023009068306300795365662712861011872933904331764909404251146367829101604918014490927524901658264139193178277114987... × 10^-10", +"mod(2.1053343141e10,pi) = mod(+(1+1015407956983808/2^52)*2.0^(34),pi) = 3.14159265358803985795440116897841971042021517833477967739316353946961929456928513638954697817331482676215697424765189761886478806761130057095656216451331963726299562891172796860029936414962898830731399848419...", +"mod(1.783366216531e12,pi) = mod(+(1+2801068395540480/2^52)*2.0^(40),pi) = 6.96948240875758165283364652450017592218369365167838571237684767728582201531913110512760529814875987841007291472111488973274399752796445730686810635597303227231604049063965142781067801484038929704503126... × 10^-13", +"mod(3.587785776203e12,pi) = mod(+(1+2844185642293248/2^52)*2.0^(41),pi) = 3.14159265358943375443615268530898643972511521351921641612349921661209466410474230079261080439434034782178672622333391220180901104555784937046215505597469325853419023536619117669842729443519112391028207634360...", +"mod(5.371151992734e12,pi) = mod(+(1+996460013189120/2^52)*2.0^(42),pi) = 3.37464214385060194766920180395831736328964513722462875515942586261884366107892162736040369453515697892612846187277924980541538489592093576898951719503435891484259641931614955023236781384150844501479806... × 10^-13", +"mod(8.958937768937e12,pi) = mod(+(1+83376510325248/2^52)*2.0^(43),pi) = 3.14159265358977121865053774550375335990551104525554538063722167948761060669100418515871869655707638819124024192122652504799628897053839090895174714955159221025369367125767543634035890939021436069166622718810...", +"mod(1.39755218526789e14,pi) = mod(+(1+4440734358344000/2^52)*2.0^(46),pi) = 7.16703280049355852405580552051994292235944787877057242894865818968232636596038712584350583584681705588885972394333979767169688540821492356534377064696422753798816392058646400432320064809223397832709837... × 10^-15", +"mod(4.28224593349304e14,pi) = mod(+(1+2347993866218368/2^52)*2.0^(48),pi) = 3.14159265358979271974893922617932552732207260508431245898085799120489745266557323213781657771845391870874778237239419162716811898993140599960797179432228824156563456394028940083212066878222733029361050389004...", +"mod(5.706674932067741e15,pi) = mod(+(1+1203075304697245/2^52)*2.0^(52),pi) = 4.23754646451256218416429262194162608653524752956234482551589924717953528741279504902951631892985510393600689510284748380679359369235443057957270202960326099424609213900534623202922619105230013018255129... × 10^-16", +"mod(6.134899525417045e15,pi) = mod(+(1+1631299898046549/2^52)*2.0^(52),pi) = 3.14159265358979314350358567743554394375133479924692111250561094743938000425549795009134531899795882166037967535790458522785762927467978667896734102976534619883583752426638882544133456931685053321622960912005..." ] + + + +## 2*pi +mod2piSolns = [ +"mod(-1.5707963267948966,2*pi) = mod(-(1+2570638124657944/2^52)*2^(0),2*pi) = 4.71238898038468991892630503228691318759905071281271164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(1.5707963267948966,2*pi) = mod(+(1+2570638124657944/2^52)*2^(0),2*pi) = 1.5707963267948965579989817342720925807952880859375", +"mod(-3.141592653589793,2*pi) = mod(-(1+2570638124657944/2^52)*2^(1),2*pi) = 3.14159265358979336092732329801482060680376262687521164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(3.141592653589793,2*pi) = mod(+(1+2570638124657944/2^52)*2^(1),2*pi) = 3.141592653589793115997963468544185161590576171875", +"mod(6.283185307179586,2*pi) = mod(+(1+2570638124657944/2^52)*2^(2),2*pi) = 6.28318530717958623199592693708837032318115234375", +"mod(-6.283185307179586,2*pi) = mod(-(1+2570638124657944/2^52)*2^(2),2*pi) = 2.44929359829470635445213186455000211641949889184615632812572417997256069650684234135964296173026564613294187689219101164463450718816256962234900568205403877042211119289245897909860763928857621951331866... × 10^-16", +"mod(45.553093477052,2*pi) = mod(+(1+1907428335405278/2^52)*2.0^(5),2*pi) = 1.57079632679489661985030232822810914211365184624851850635077570769057031199307401920751244521036104824992678881404770694068617546629184875584496828620126435569602256217286070452216497527871463097465249799664...", +"mod(3.14159265359,2*pi) = mod(+(1+2570638124658410/2^52)*2.0^(1),2*pi) = 3.14159265359000006156975359772332012653350830078125", +"mod(-3.14159265359,2*pi) = mod(-(1+2570638124658410/2^52)*2.0^(1),2*pi) = 3.14159265358958641535553316883568564186083049796896164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.9269808169872418,2*pi) = mod(-(1+4339175044666918/2^52)*2.0^(1),2*pi) = 2.35620449019234470335066281789739528427110881828146164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.73063127613788,2*pi) = mod(-(1+3897035185165141/2^52)*2.0^(1),2*pi) = 2.55255403104170655105593060965009877214418621085958664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.5342817352885176,2*pi) = mod(-(1+3454895325663363/2^52)*2.0^(1),2*pi) = 2.74890357189106884285040825146541842946993083976583664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.337932194439156,2*pi) = mod(-(1+3012755466161586/2^52)*2.0^(1),2*pi) = 2.94525311274043069055567604321812191734300823234396164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.1415826535897935,2*pi) = mod(-(1+2570615606659808/2^52)*2.0^(1),2*pi) = 3.14160265358979298235015368503344157466875286125021164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.9452331127404316,2*pi) = mod(-(1+2128475747158031/2^52)*2.0^(1),2*pi) = 3.33795219443915483005542147678614506254183025382833664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.7488835718910694,2*pi) = mod(-(1+1686335887656253/2^52)*2.0^(1),2*pi) = 3.53430173528851712184989911860146471986757488273458664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.5525340310417075,2*pi) = mod(-(1+1244196028154476/2^52)*2.0^(1),2*pi) = 3.73065127613787896955516691035416820774065227531271164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.356184490192345,2*pi) = mod(-(1+802056168652698/2^52)*2.0^(1),2*pi) = 3.92700081698724126134964455216948786506639690421896164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.1598349493429834,2*pi) = mod(-(1+359916309150921/2^52)*2.0^(1),2*pi) = 4.12335035783660310905491234392219135293947429679708664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.9634854084936209,2*pi) = mod(-(1+4339152526668781/2^52)*2.0^(0),2*pi) = 4.31969989868596562289399491076881909499155254386739914194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.7671358676442588,2*pi) = mod(-(1+3454872807665226/2^52)*2.0^(0),2*pi) = 4.51604943953532769264386762755283066759096355460958664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.5707863267948967,2*pi) = mod(-(1+2570593088661671/2^52)*2.0^(0),2*pi) = 4.71239898038468976239374034433684224019037456535177414194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.3744367859455346,2*pi) = mod(-(1+1686313369658116/2^52)*2.0^(0),2*pi) = 4.90874852123405183214361306112085381278978557609396164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.1780872450961726,2*pi) = mod(-(1+802033650654561/2^52)*2.0^(0),2*pi) = 5.10509806208341390189348577790486538538919658683614914194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.9817377042468104,2*pi) = mod(-(1+4339107490672507/2^52)*2.0^(-1),2*pi) = 5.30144760293277608266566095720453100035177440666036789194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.7853881633974483,2*pi) = mod(-(1+2570548052665397/2^52)*2.0^(-1),2*pi) = 5.49779714378213815241553367398854257295118541740255539194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.5890386225480863,2*pi) = mod(-(1+801988614658287/2^52)*2.0^(-1),2*pi) = 5.69414668463150022216540639077255414555059642814474289194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.3926890816987242,2*pi) = mod(-(1+2570457980672850/2^52)*2.0^(-2),2*pi) = 5.89049622548086229191527910755656571815000743888693039194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.1963395408493621,2*pi) = mod(-(1+2570277836687755/2^52)*2.0^(-3),2*pi) = 6.08684576633022438942072743996949080134021015189962570444988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(1.0e-5,2*pi) = mod(+(1+1399358476216561/2^52)*2.0^(-17),2*pi) = 0.000010000000000000000818030539140313095458623138256371021270751953125", +"mod(0.19635954084936205,2*pi) = mod(+(1+2570998412628133/2^52)*2.0^(-3),2*pi) = 0.1963595408493620519951861069785081781446933746337890625", +"mod(0.3927090816987241,2*pi) = mod(+(1+2570818268643038/2^52)*2.0^(-2),2*pi) = 0.39270908169872409398948320813360624015331268310546875", +"mod(0.5890586225480862,2*pi) = mod(+(1+802168758643381/2^52)*2.0^(-1),2*pi) = 0.58905862254808616373935592491761781275272369384765625", +"mod(0.7854081633974482,2*pi) = mod(+(1+2570728196650491/2^52)*2.0^(-1),2*pi) = 0.78540816339744823348922864170162938535213470458984375", +"mod(0.9817577042468103,2*pi) = mod(+(1+4339287634657601/2^52)*2.0^(-1),2*pi) = 0.98175770424681030323910135848564095795154571533203125", +"mod(1.1781072450961723,2*pi) = mod(+(1+802123722647107/2^52)*2.0^(0),2*pi) = 1.1781072450961722619666716127539984881877899169921875", +"mod(1.3744567859455343,2*pi) = mod(+(1+1686403441650662/2^52)*2.0^(0),2*pi) = 1.374456785945534331716544329538010060787200927734375", +"mod(1.5708063267948964,2*pi) = mod(+(1+2570683160654217/2^52)*2.0^(0),2*pi) = 1.5708063267948964014664170463220216333866119384765625", +"mod(1.7671558676442585,2*pi) = mod(+(1+3454962879657772/2^52)*2.0^(0),2*pi) = 1.76715586764425847121628976310603320598602294921875", +"mod(1.9635054084936205,2*pi) = mod(+(1+4339242598661327/2^52)*2.0^(0),2*pi) = 1.9635054084936205409661624798900447785854339599609375", +"mod(2.159854949342982,2*pi) = mod(+(1+359961345147192/2^52)*2.0^(1),2*pi) = 2.159854949342982166626825346611440181732177734375", +"mod(2.3562044901923445,2*pi) = mod(+(1+802101204648970/2^52)*2.0^(1),2*pi) = 2.35620449019234445842130298842675983905792236328125", +"mod(2.5525540310417063,2*pi) = mod(+(1+1244241064150747/2^52)*2.0^(1),2*pi) = 2.552554031041706306126570780179463326930999755859375", +"mod(2.7489035718910686,2*pi) = mod(+(1+1686380923652525/2^52)*2.0^(1),2*pi) = 2.748903571891068597921048421994782984256744384765625", +"mod(2.9452531127404304,2*pi) = mod(+(1+2128520783154302/2^52)*2.0^(1),2*pi) = 2.94525311274043044562631621374748647212982177734375", +"mod(3.1416026535897927,2*pi) = mod(+(1+2570660642656080/2^52)*2.0^(1),2*pi) = 3.14160265358979273742079385556280612945556640625", +"mod(3.3379521944391546,2*pi) = mod(+(1+3012800502157857/2^52)*2.0^(1),2*pi) = 3.337952194439154585126061647315509617328643798828125", +"mod(3.534301735288517,2*pi) = mod(+(1+3454940361659635/2^52)*2.0^(1),2*pi) = 3.534301735288516876920539289130829274654388427734375", +"mod(3.7306512761378787,2*pi) = mod(+(1+3897080221161412/2^52)*2.0^(1),2*pi) = 3.7306512761378787246258070808835327625274658203125", +"mod(3.927000816987241,2*pi) = mod(+(1+4339220080663190/2^52)*2.0^(1),2*pi) = 3.92700081698724101642028472269885241985321044921875", +"mod(-3.9270008169872415,2*pi) = mod(-(1+4339220080663191/2^52)*2.0^(1),2*pi) = 2.35618449019234501641579219379753717908846111320333664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.7306512761378796,2*pi) = mod(-(1+3897080221161414/2^52)*2.0^(1),2*pi) = 2.55253403104170686412105998555024066696153850578146164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.5343017352885173,2*pi) = mod(-(1+3454940361659636/2^52)*2.0^(1),2*pi) = 2.74888357189106915591553762736556032428728313468771164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.3379521944391555,2*pi) = mod(-(1+3012800502157859/2^52)*2.0^(1),2*pi) = 2.94523311274043100362080541911826381216036052726583664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-3.141602653589793,2*pi) = mod(-(1+2570660642656081/2^52)*2.0^(1),2*pi) = 3.14158265358979329541528306093358346948610515617208664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.9452531127404313,2*pi) = mod(-(1+2128520783154304/2^52)*2.0^(1),2*pi) = 3.33793219443915514312055085268628695735918254875021164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.748903571891069,2*pi) = mod(-(1+1686380923652526/2^52)*2.0^(1),2*pi) = 3.53428173528851743491502849450160661468492717765646164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.552554031041707,2*pi) = mod(-(1+1244241064150749/2^52)*2.0^(1),2*pi) = 3.73063127613787928262029628625431010255800457023458664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.356204490192345,2*pi) = mod(-(1+802101204648971/2^52)*2.0^(1),2*pi) = 3.92698081698724157441477392806962975988374919914083664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-2.159854949342983,2*pi) = mod(-(1+359961345147194/2^52)*2.0^(1),2*pi) = 4.12333035783660342212004171982233324775682659171896164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.9635054084936208,2*pi) = mod(-(1+4339242598661328/2^52)*2.0^(0),2*pi) = 4.31967989868596571391451936163765290508257122062521164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.7671558676442587,2*pi) = mod(-(1+3454962879657773/2^52)*2.0^(0),2*pi) = 4.51602943953532778366439207842166447768198223136739914194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.5708063267948966,2*pi) = mod(-(1+2570683160654218/2^52)*2.0^(0),2*pi) = 4.71237898038468985341426479520567605028139324210958664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.3744567859455346,2*pi) = mod(-(1+1686403441650663/2^52)*2.0^(0),2*pi) = 4.90872852123405192316413751198968762288080425285177414194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.1781072450961725,2*pi) = mod(-(1+802123722647108/2^52)*2.0^(0),2*pi) = 5.10507806208341399291401022877369919548021526359396164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.9817577042468104,2*pi) = mod(-(1+4339287634657602/2^52)*2.0^(-1),2*pi) = 5.30142760293277606266388294555771076807962627433614914194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.7854081633974483,2*pi) = mod(-(1+2570728196650492/2^52)*2.0^(-1),2*pi) = 5.49777714378213813241375566234172234067903728507833664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.5890586225480863,2*pi) = mod(-(1+802168758643382/2^52)*2.0^(-1),2*pi) = 5.69412668463150020216362837912573391327844829582052414194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.39270908169872415,2*pi) = mod(-(1+2570818268643039/2^52)*2.0^(-2),2*pi) = 5.89047622548086232742465232716757250705944271110372726694988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-0.19635954084936208,2*pi) = mod(-(1+2570998412628134/2^52)*2.0^(-3),2*pi) = 6.08682576633022439717452504395158407965885372184591476694988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(-1.0e-5,2*pi) = mod(-(1+1399358476216561/2^52)*2.0^(-17),2*pi) = 6.28317530717958647692446873601986545529888017561195527092861843266250781257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", +"mod(0.19633954084936206,2*pi) = mod(+(1+2570277836687754/2^52)*2.0^(-3),2*pi) = 0.196339540849362059748983710960601456463336944580078125", +"mod(0.39268908169872413,2*pi) = mod(+(1+2570457980672849/2^52)*2.0^(-2),2*pi) = 0.392689081698724129498856427744613029062747955322265625", +"mod(0.5890386225480861,2*pi) = mod(+(1+801988614658286/2^52)*2.0^(-1),2*pi) = 0.5890386225480861437375779132707975804805755615234375", +"mod(0.7853881633974482,2*pi) = mod(+(1+2570548052665396/2^52)*2.0^(-1),2*pi) = 0.785388163397448213487450630054809153079986572265625", +"mod(0.9817377042468103,2*pi) = mod(+(1+4339107490672506/2^52)*2.0^(-1),2*pi) = 0.9817377042468102832373233468388207256793975830078125", +"mod(1.1780872450961724,2*pi) = mod(+(1+802033650654560/2^52)*2.0^(0),2*pi) = 1.17808724509617235298719606362283229827880859375", +"mod(1.3744367859455344,2*pi) = mod(+(1+1686313369658115/2^52)*2.0^(0),2*pi) = 1.3744367859455344227370687804068438708782196044921875", +"mod(1.5707863267948965,2*pi) = mod(+(1+2570593088661670/2^52)*2.0^(0),2*pi) = 1.570786326794896492486941497190855443477630615234375", +"mod(1.7671358676442586,2*pi) = mod(+(1+3454872807665225/2^52)*2.0^(0),2*pi) = 1.7671358676442585622368142139748670160770416259765625", +"mod(1.9634854084936206,2*pi) = mod(+(1+4339152526668780/2^52)*2.0^(0),2*pi) = 1.96348540849362063198668693075887858867645263671875", +"mod(2.1598349493429825,2*pi) = mod(+(1+359916309150919/2^52)*2.0^(1),2*pi) = 2.159834949342982479691954722511582076549530029296875", +"mod(2.3561844901923448,2*pi) = mod(+(1+802056168652697/2^52)*2.0^(1),2*pi) = 2.356184490192344771486432364326901733875274658203125", +"mod(2.5525340310417066,2*pi) = mod(+(1+1244196028154474/2^52)*2.0^(1),2*pi) = 2.55253403104170661919170015607960522174835205078125", +"mod(2.748883571891069,2*pi) = mod(+(1+1686335887656252/2^52)*2.0^(1),2*pi) = 2.7488835718910689109861777978949248790740966796875", +"mod(2.9452331127404308,2*pi) = mod(+(1+2128475747158029/2^52)*2.0^(1),2*pi) = 2.945233112740430758691445589647628366947174072265625", +"mod(3.141582653589793,2*pi) = mod(+(1+2570615606659807/2^52)*2.0^(1),2*pi) = 3.141582653589793050485923231462948024272918701171875", +"mod(3.337932194439155,2*pi) = mod(+(1+3012755466161584/2^52)*2.0^(1),2*pi) = 3.33793219443915489819119102321565151214599609375", +"mod(3.534281735288517,2*pi) = mod(+(1+3454895325663362/2^52)*2.0^(1),2*pi) = 3.53428173528851718998566866503097116947174072265625", +"mod(3.730631276137879,2*pi) = mod(+(1+3897035185165139/2^52)*2.0^(1),2*pi) = 3.730631276137879037690936456783674657344818115234375", +"mod(3.9269808169872413,2*pi) = mod(+(1+4339175044666917/2^52)*2.0^(1),2*pi) = 3.926980816987241329485414098598994314670562744140625", +"mod(22.0,2*pi) = mod(+(1+1688849860263936/2^52)*2.0^(4),2*pi) = 3.15044407846124056922413970032298269481698360374936507415033244615310156228274600823179104794729759210711148092030616011743693234269650660964784355122911329529829538378836887336664213226230627041770821342713...", +"mod(333.0,2*pi) = mod(+(1+1354598325420032/2^52)*2.0^(8),2*pi) = 6.27436402666150319988508813893170004349438246498899461860576239998709374623426414268437816441982492985659900261864010870224016060673944790056262155463796378517045331899839380502179695921330868724027569940365...", +"mod(355.0,2*pi) = mod(+(1+1741626418397184/2^52)*2.0^(8),2*pi) = 3.14162279794315729218394107269567696991702726998814805080620566152456249594459215366009956168288838599941431051238165552548940373033479004675974628961011484556818049738288563617731980222971704779721998397317...", +"mod(103993.0,2*pi) = mod(+(1+2642744916836352/2^52)*2.0^(16),2*pi) = 6.28316617784380688650401344845453307369288068399732572933399461127695192648214541204728117592504979089833641035564998119374342387572812989060359094727501239559620056583495140597576298038959180435697740635670...", +"mod(104348.0,2*pi) = mod(+(1+2667140331077632/2^52)*2.0^(16),2*pi) = 3.14160366860737770176266775459120427521556915523526213819031108818588160985431956845131108692370404093345454784146702342504513838696175547391261842062816500626381285781395999994196349337341094229343346147225...", +"mod(208341.0,2*pi) = mod(+(1+2654942623956992/2^52)*2.0^(17),2*pi) = 3.14158453927159811134139443648673158051411104048237622557441651484720072376404698324252261216451969586749478517055239132460087304358872090106549055164621516695944521824503436370660718451710483678964693897133...", +"mod(312689.0,2*pi) = mod(+(1+868356487905280/2^52)*2.0^(18),2*pi) = 2.90069938933617877542451893008733534139696742672181483841841744952104594855443776404840398960083665315998545480145545832221144931191152739015601741793832268987065511732143745138864461786922231647158597... × 10^-6", +"mod(833719.0,2*pi) = mod(+(1+2657992050737152/2^52)*2.0^(19),2*pi) = 3.14159034067037678369894528552459175518479383441722966920409335168209976585594409211805070897249889754080110514146199423551751746648734472412027086368105104360482495955526900658150996180634057523427988214327...", +"mod(1.146408e6,2*pi) = mod(+(1+420185240502272/2^52)*2.0^(20),2*pi) = 3.14159324136976611987772071004352184252013523138465639101893177009954928690189264655581475737648849837745426512691679569097583967793665663564766101969846898192751483021038632801896135045095844445659635372924...", +"mod(4.272943e6,2*pi) = mod(+(1+84437983297536/2^52)*2.0^(22),2*pi) = 6.28318475760008866640682064909615151435086072982098720031099947736511481398920403452942533041773025670886772749564776801425734728119615016761253510651949575448680124478255094842727472391331799874330501447339...", +"mod(5.419351e6,2*pi) = mod(+(1+1315384200265728/2^52)*2.0^(22),2*pi) = 3.14159269179026830935925459258066758847665716245543194938004206284903128831867868382917043710998461912202581959599995041104549774003164233980947730996100250151374786958906023423511678511837853333913743934502...", +"mod(8.0143857e7,2*pi) = mod(+(1+874763572477952/2^52)*2.0^(26),2*pi) = 6.28318529240673965895937757931245737426368941294555299798236406494212316244377962734532389516787597266715599065369478070958049110793099168079018573217479513137529398120225493224107469084933209646588166330039...", +"mod(1.65707065e8,2*pi) = mod(+(1+1056606817091584/2^52)*2.0^(27),2*pi) = 3.14159266224457467342743621808757080021535839084611466144499182350201198806140194400767892607726829252774545485026028524183110151769129677448841114179666829446319942118581601429502758832524690654937290823057...", +"mod(2.45850922e8,2*pi) = mod(+(1+3745788417015808/2^52)*2.0^(27),2*pi) = 3.14159264747172785546152703084102240608470900504145601747746670382850233793276357409693317056091012923060527247739045265722390340652112399182787805771450119093792519698419390432498298992868109315449064267334...", +"mod(4.11557987e8,2*pi) = mod(+(1+2401197617053696/2^52)*2.0^(28),2*pi) = 2.53671605196367648236958743790572859713735903697256934271488151342174752084854244595394428579405455430108612460486731570511125630286557038325420725050055641276613287640889128900803008984309962204629913... × 10^-9", +"mod(1.068966896e9,2*pi) = mod(+(1+4463544628150272/2^52)*2.0^(29),2*pi) = 3.14159265254515995938887999558019728189616619931617409142260538925826536477625861579401806246879870081871438107956270186695853481674363659755901882422291569193903802251645965714276556794474127284068988676594...", +"mod(2.549491779e9,2*pi) = mod(+(1+843072155942912/2^52)*2.0^(31),2*pi) = 4.47449493816149706970976233303722197019495577867890936615779430401846755180508920207307551467187143433646915044596696119497365034532889215443076399478064252395175148483303135651614725663715466720569020... × 10^-10", +"mod(6.167950454e9,2*pi) = mod(+(1+1963965187883008/2^52)*2.0^(32),2*pi) = 3.14159265344005894702117940952214974850361059335516524715838726248982422557995212615503590288341380375308866794685653195615192705573836666662479725510906849089516652730680995410937183924797072416812082020708...", +"mod(1.4885392687e10,2*pi) = mod(+(1+3300633133711360/2^52)*2.0^(33),2*pi) = 1.47980910933221759456269961916604584979614430234776276979795068989333010234511075289901023009068306300795365662712861011872933904331764909404251146367829101604918014490927524901658264139193178277114987... × 10^-10", +"mod(2.1053343141e10,2*pi) = mod(+(1+1015407956983808/2^52)*2.0^(34),2*pi) = 3.14159265358803985795440116897841971042021517833477967739316353946961929456928513638954697817331482676215697424765189761886478806761130057095656216451331963726299562891172796860029936414962898830731399848419...", +"mod(1.783366216531e12,2*pi) = mod(+(1+2801068395540480/2^52)*2.0^(40),2*pi) = 6.96948240875758165283364652450017592218369365167838571237684767728582201531913110512760529814875987841007291472111488973274399752796445730686810635597303227231604049063965142781067801484038929704503126... × 10^-13", +"mod(3.587785776203e12,2*pi) = mod(+(1+2844185642293248/2^52)*2.0^(41),2*pi) = 3.14159265358943375443615268530898643972511521351921641612349921661209466410474230079261080439434034782178672622333391220180901104555784937046215505597469325853419023536619117669842729443519112391028207634360...", +"mod(5.371151992734e12,2*pi) = mod(+(1+996460013189120/2^52)*2.0^(42),2*pi) = 3.14159265359013070267702844347426980437756523111143478548866705518333234887247088299414271750485310835160160221117491949328112253453112377021495150170538006916978753859342278074749125957797219171176611527331...", +"mod(8.958937768937e12,2*pi) = mod(+(1+83376510325248/2^52)*2.0^(43),2*pi) = 6.28318530717956445711318112878325624410268044463065120161216627179542701297721318378675352189919345617338832843450883169509013358008897314067710655768007332770397777395961395744591855401316331562204819161692...", +"mod(1.39755218526789e14,2*pi) = mod(+(1+4440734358344000/2^52)*2.0^(46),2*pi) = 3.14159265358980040549544387683802694000268991931802818042282336288024535494439868095440078572924291148798393333033819550681778794934825392861076762305204646122093106692947650926948023108695327813103005666278...", +"mod(4.28224593349304e14,2*pi) = mod(+(1+2347993866218368/2^52)*2.0^(48),2*pi) = 3.14159265358979271974893922617932552732207260508431245898085799120489745266557323213781657771845391870874778237239419162716811898993140599960797179432228824156563456394028940083212066878222733029361050389004...", +"mod(5.706674932067741e15,2*pi) = mod(+(1+1203075304697245/2^52)*2.0^(52),2*pi) = 4.23754646451256218416429262194162608653524752956234482551589924717953528741279504902951631892985510393600689510284748380679359369235443057957270202960326099424609213900534623202922619105230013018255129... × 10^-16", +"mod(6.134899525417045e15,2*pi) = mod(+(1+1631299898046549/2^52)*2.0^(52),2*pi) = 3.14159265358979314350358567743554394375133479924692111250561094743938000425549795009134531899795882166037967535790458522785762927467978667896734102976534619883583752426638882544133456931685053321622960912005..." +] + + + + +## pi/2 +modpio2Solns = [ +"mod(-1.5707963267948966,pi/2) = mod(-(1+2570638124657944/2^52)*2^(0),pi/2) = 6.12323399573676588613032966137500529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667... × 10^-17", +"mod(1.5707963267948966,pi/2) = mod(+(1+2570638124657944/2^52)*2^(0),pi/2) = 1.5707963267948965579989817342720925807952880859375", +"mod(-3.141592653589793,pi/2) = mod(-(1+2570638124657944/2^52)*2^(1),pi/2) = 1.22464679914735317722606593227500105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933... × 10^-16", +"mod(3.141592653589793,pi/2) = mod(+(1+2570638124657944/2^52)*2^(1),pi/2) = 1.57079632679489649676664177690443371949199147218744708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(6.283185307179586,pi/2) = mod(+(1+2570638124657944/2^52)*2^(2),pi/2) = 1.57079632679489637430196186216911599688539824468734126853758311153827539057068650205794776198682439802677787023007654002935923308567412665241196088780727832382457384594709221834166053306557656760442705335678...", +"mod(-6.283185307179586,pi/2) = mod(-(1+2570638124657944/2^52)*2^(2),pi/2) = 2.44929359829470635445213186455000211641949889184615632812572417997256069650684234135964296173026564613294187689219101164463450718816256962234900568205403877042211119289245897909860763928857621951331866... × 10^-16", +"mod(45.553093477052,pi/2) = mod(+(1+1907428335405278/2^52)*2.0^(5),pi/2) = 6.18980636588357700015067146560965595863303411536662108849969519893495032539302514258852745557406553617139253161516557639982288582137023796970880510821891443969385152967240153509461515782240852843965031... × 10^-19", +"mod(3.14159265359,pi/2) = mod(+(1+2570638124658410/2^52)*2.0^(1),pi/2) = 2.06823107110214443817242336338901406144179025055407692183593713791001371965174657882932017851913486717693352906155390449417768274640591871518882549715897298061478894440355377051045069618035571189024334... × 10^-13", +"mod(-3.14159265359,pi/2) = mod(-(1+2570638124658410/2^52)*2.0^(1),pi/2) = 1.57079632679468979612421147719593419976224579828140873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.9269808169872418,pi/2) = mod(-(1+4339175044666918/2^52)*2.0^(1),pi/2) = 0.78540816339744808411934112625764384217252411859390873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.73063127613788,pi/2) = mod(-(1+3897035185165141/2^52)*2.0^(1),pi/2) = 0.98175770424680993182460891801034733004560151117203373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.5342817352885176,pi/2) = mod(-(1+3454895325663363/2^52)*2.0^(1),pi/2) = 1.17810724509617222361908655982566698737134614007828373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.337932194439156,pi/2) = mod(-(1+3012755466161586/2^52)*2.0^(1),pi/2) = 1.37445678594553407132435435157837047524442353265640873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.1415826535897935,pi/2) = mod(-(1+2570615606659808/2^52)*2.0^(1),pi/2) = 9.9999999997438875103017539386904715834618751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288... × 10^-6", +"mod(-2.9452331127404316,pi/2) = mod(-(1+2128475747158031/2^52)*2.0^(1),pi/2) = 0.19635954084936159159277809350664217834466085445323082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.7488835718910694,pi/2) = mod(-(1+1686335887656253/2^52)*2.0^(1),pi/2) = 0.39270908169872388338725573532196183567040548335948082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.5525340310417075,pi/2) = mod(-(1+1244196028154476/2^52)*2.0^(1),pi/2) = 0.58905862254808573109252352707466532354348287593760582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.356184490192345,pi/2) = mod(-(1+802056168652698/2^52)*2.0^(1),pi/2) = 0.78540816339744802288700116888998498086922750484385582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.1598349493429834,pi/2) = mod(-(1+359916309150921/2^52)*2.0^(1),pi/2) = 0.98175770424680987059226896064268846874230489742198082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.9634854084936209,pi/2) = mod(-(1+4339152526668781/2^52)*2.0^(0),pi/2) = 1.17810724509617238443135152748931621079438314449229332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.7671358676442588,pi/2) = mod(-(1+3454872807665226/2^52)*2.0^(0),pi/2) = 1.37445678594553445418122424427332778339379415523448082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.5707863267948967,pi/2) = mod(-(1+2570593088661671/2^52)*2.0^(0),pi/2) = 9.9999999999046997752694175879138946204662891154104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144... × 10^-6", +"mod(-1.3744367859455346,pi/2) = mod(-(1+1686313369658116/2^52)*2.0^(0),pi/2) = 0.19635954084936197444964798620159948649403147703130291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-1.1780872450961726,pi/2) = mod(-(1+802033650654561/2^52)*2.0^(0),pi/2) = 0.39270908169872404419952070298561105909344248777349041048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.9817377042468104,pi/2) = mod(-(1+4339107490672507/2^52)*2.0^(-1),pi/2) = 0.58905862254808622497169588228527667405602030759770916048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.7853881633974483,pi/2) = mod(-(1+2570548052665397/2^52)*2.0^(-1),pi/2) = 0.78540816339744829472156859906928824665543131833989666048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.5890386225480863,pi/2) = mod(-(1+801988614658287/2^52)*2.0^(-1),pi/2) = 0.98175770424681036447144131585329981925484232908208416048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.3926890816987242,pi/2) = mod(-(1+2570457980672850/2^52)*2.0^(-2),pi/2) = 1.17810724509617243422131403263731139185425333982427166048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.1963395408493621,pi/2) = mod(-(1+2570277836687755/2^52)*2.0^(-3),pi/2) = 1.37445678594553453172676236505023647504445605283696697298747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(1.0e-5,pi/2) = mod(+(1+1399358476216561/2^52)*2.0^(-17),pi/2) = 0.000010000000000000000818030539140313095458623138256371021270751953125", +"mod(0.19635954084936205,pi/2) = mod(+(1+2570998412628133/2^52)*2.0^(-3),pi/2) = 0.1963595408493620519951861069785081781446933746337890625", +"mod(0.3927090816987241,pi/2) = mod(+(1+2570818268643038/2^52)*2.0^(-2),pi/2) = 0.39270908169872409398948320813360624015331268310546875", +"mod(0.5890586225480862,pi/2) = mod(+(1+802168758643381/2^52)*2.0^(-1),pi/2) = 0.58905862254808616373935592491761781275272369384765625", +"mod(0.7854081633974482,pi/2) = mod(+(1+2570728196650491/2^52)*2.0^(-1),pi/2) = 0.78540816339744823348922864170162938535213470458984375", +"mod(0.9817577042468103,pi/2) = mod(+(1+4339287634657601/2^52)*2.0^(-1),pi/2) = 0.98175770424681030323910135848564095795154571533203125", +"mod(1.1781072450961723,pi/2) = mod(+(1+802123722647107/2^52)*2.0^(0),pi/2) = 1.1781072450961722619666716127539984881877899169921875", +"mod(1.3744567859455343,pi/2) = mod(+(1+1686403441650662/2^52)*2.0^(0),pi/2) = 1.374456785945534331716544329538010060787200927734375", +"mod(1.5708063267948964,pi/2) = mod(+(1+2570683160654217/2^52)*2.0^(0),pi/2) = 9.9999999997822350953546822701912880272387890095895125277038460917968568955006859825873289414660089259567433588466764530776952247088841373202959357594412748579486490307394472201776885255225348090177856... × 10^-6", +"mod(1.7671558676442585,pi/2) = mod(+(1+3454962879657772/2^52)*2.0^(0),pi/2) = 0.19635954084936185198496807146628176388743824953119708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(1.9635054084936205,pi/2) = mod(+(1+4339242598661327/2^52)*2.0^(0),pi/2) = 0.39270908169872392173484078825029333648684926027338458951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.159854949342982,pi/2) = mod(+(1+359961345147192/2^52)*2.0^(1),pi/2) = 0.58905862254808554739550365497168873963359303468744708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.3562044901923445,pi/2) = mod(+(1+802101204648970/2^52)*2.0^(1),pi/2) = 0.78540816339744783918998129678700839695933766359369708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.5525540310417063,pi/2) = mod(+(1+1244241064150747/2^52)*2.0^(1),pi/2) = 0.98175770424680968689524908853971188483241505617182208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.7489035718910686,pi/2) = mod(+(1+1686380923652525/2^52)*2.0^(1),pi/2) = 1.17810724509617197868972673035503154215815968507807208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.9452531127404304,pi/2) = mod(+(1+2128520783154302/2^52)*2.0^(1),pi/2) = 1.37445678594553382639499452210773503003123707765619708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(3.1416026535897927,pi/2) = mod(+(1+2570660642656080/2^52)*2.0^(1),pi/2) = 9.9999999994989581504722833032452583970068748941790250554076921835937137910013719651746578829320178519134867176933529061553904494177682746405918715188825497158972980614788944403553770510450696180355712... × 10^-6", +"mod(3.3379521944391546,pi/2) = mod(+(1+3012800502157857/2^52)*2.0^(1),pi/2) = 0.19635954084936134666341826403600673313147439945301917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.534301735288517,pi/2) = mod(+(1+3454940361659635/2^52)*2.0^(1),pi/2) = 0.39270908169872363845789590585132639045721902835926917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.7306512761378787,pi/2) = mod(+(1+3897080221161412/2^52)*2.0^(1),pi/2) = 0.58905862254808548616316369760402987833029642093739417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.927000816987241,pi/2) = mod(+(1+4339220080663190/2^52)*2.0^(1),pi/2) = 0.78540816339744777795764133941934953565604104984364417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(-3.9270008169872415,pi/2) = mod(-(1+4339220080663191/2^52)*2.0^(1),pi/2) = 0.78538816339744839718447050215778573698987641351578373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.7306512761378796,pi/2) = mod(-(1+3897080221161414/2^52)*2.0^(1),pi/2) = 0.98173770424681024488973829391048922486295380609390873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.5343017352885173,pi/2) = mod(-(1+3454940361659636/2^52)*2.0^(1),pi/2) = 1.17808724509617253668421593572580888218869843500015873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.3379521944391555,pi/2) = mod(-(1+3012800502157859/2^52)*2.0^(1),pi/2) = 1.37443678594553438438948372747851237006177582757828373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-3.141602653589793,pi/2) = mod(-(1+2570660642656081/2^52)*2.0^(1),pi/2) = 1.57078632679489667618396136929383202738752045648453373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", +"mod(-2.9452531127404313,pi/2) = mod(-(1+2128520783154304/2^52)*2.0^(1),pi/2) = 0.19633954084936190465790746940678407316201314937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.748903571891069,pi/2) = mod(-(1+1686380923652526/2^52)*2.0^(1),pi/2) = 0.39268908169872419645238511122210373048775777828135582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.552554031041707,pi/2) = mod(-(1+1244241064150749/2^52)*2.0^(1),pi/2) = 0.58903862254808604415765290297480721836083517085948082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.356204490192345,pi/2) = mod(-(1+802101204648971/2^52)*2.0^(1),pi/2) = 0.78538816339744833595213054479012687568657979976573082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-2.159854949342983,pi/2) = mod(-(1+359961345147194/2^52)*2.0^(1),pi/2) = 0.98173770424681018365739833654283036355965719234385582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.9635054084936208,pi/2) = mod(-(1+4339242598661328/2^52)*2.0^(0),pi/2) = 1.17808724509617247545187597835815002088540182125010582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.7671558676442587,pi/2) = mod(-(1+3454962879657773/2^52)*2.0^(0),pi/2) = 1.37443678594553454520174869514216159348481283199229332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.5708063267948966,pi/2) = mod(-(1+2570683160654218/2^52)*2.0^(0),pi/2) = 1.57078632679489661495162141192617316608422384273448082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", +"mod(-1.3744567859455346,pi/2) = mod(-(1+1686403441650663/2^52)*2.0^(0),pi/2) = 0.19633954084936206547017243707043329658505015378911541048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-1.1781072450961725,pi/2) = mod(-(1+802123722647108/2^52)*2.0^(0),pi/2) = 0.39268908169872413522004515385444486918446116453130291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.9817577042468104,pi/2) = mod(-(1+4339287634657602/2^52)*2.0^(-1),pi/2) = 0.58903862254808620496991787063845644178387217527349041048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.7854081633974483,pi/2) = mod(-(1+2570728196650492/2^52)*2.0^(-1),pi/2) = 0.78538816339744827471979058742246801438328318601567791048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.5890586225480863,pi/2) = mod(-(1+802168758643382/2^52)*2.0^(-1),pi/2) = 0.98173770424681034446966330420647958698269419675786541048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.39270908169872415,pi/2) = mod(-(1+2570818268643039/2^52)*2.0^(-2),pi/2) = 1.17808724509617246973068725224831818076368861204106853548747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-0.19635954084936208,pi/2) = mod(-(1+2570998412628134/2^52)*2.0^(-3),pi/2) = 1.37443678594553453948055996903232975336309962278325603548747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(-1.0e-5,pi/2) = mod(-(1+1399358476216561/2^52)*2.0^(-17),pi/2) = 1.57078632679489661923050366110061112900312607654929653946620154420078320314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", +"mod(0.19633954084936206,pi/2) = mod(+(1+2570277836687754/2^52)*2.0^(-3),pi/2) = 0.196339540849362059748983710960601456463336944580078125", +"mod(0.39268908169872413,pi/2) = mod(+(1+2570457980672849/2^52)*2.0^(-2),pi/2) = 0.392689081698724129498856427744613029062747955322265625", +"mod(0.5890386225480861,pi/2) = mod(+(1+801988614658286/2^52)*2.0^(-1),pi/2) = 0.5890386225480861437375779132707975804805755615234375", +"mod(0.7853881633974482,pi/2) = mod(+(1+2570548052665396/2^52)*2.0^(-1),pi/2) = 0.785388163397448213487450630054809153079986572265625", +"mod(0.9817377042468103,pi/2) = mod(+(1+4339107490672506/2^52)*2.0^(-1),pi/2) = 0.9817377042468102832373233468388207256793975830078125", +"mod(1.1780872450961724,pi/2) = mod(+(1+802033650654560/2^52)*2.0^(0),pi/2) = 1.17808724509617235298719606362283229827880859375", +"mod(1.3744367859455344,pi/2) = mod(+(1+1686313369658115/2^52)*2.0^(0),pi/2) = 1.3744367859455344227370687804068438708782196044921875", +"mod(1.5707863267948965,pi/2) = mod(+(1+2570593088661670/2^52)*2.0^(0),pi/2) = 1.570786326794896492486941497190855443477630615234375", +"mod(1.7671358676442586,pi/2) = mod(+(1+3454872807665225/2^52)*2.0^(0),pi/2) = 0.19633954084936194300549252233511557397845692628900958951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(1.9634854084936206,pi/2) = mod(+(1+4339152526668780/2^52)*2.0^(0),pi/2) = 0.39268908169872401275536523911912714657786793703119708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.1598349493429825,pi/2) = mod(+(1+359916309150919/2^52)*2.0^(1),pi/2) = 0.58903862254808586046063303087183063445094532960932208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.3561844901923448,pi/2) = mod(+(1+802056168652697/2^52)*2.0^(1),pi/2) = 0.78538816339744815225511067268715029177668995851557208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.5525340310417066,pi/2) = mod(+(1+1244196028154474/2^52)*2.0^(1),pi/2) = 0.98173770424680999996037846443985377964976735109369708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.748883571891069,pi/2) = mod(+(1+1686335887656252/2^52)*2.0^(1),pi/2) = 1.17808724509617229175485610625517343697551197999994708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(2.9452331127404308,pi/2) = mod(+(1+2128475747158029/2^52)*2.0^(1),pi/2) = 1.37443678594553413946012389800787692484858937257807208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(3.141582653589793,pi/2) = mod(+(1+2570615606659807/2^52)*2.0^(1),pi/2) = 1.57078632679489643125460153982319658217433400148432208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", +"mod(3.337932194439155,pi/2) = mod(+(1+3012755466161584/2^52)*2.0^(1),pi/2) = 0.19633954084936165972854763993614862794882669437489417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.534281735288517,pi/2) = mod(+(1+3454895325663362/2^52)*2.0^(1),pi/2) = 0.39268908169872395152302528175146828527457132328114417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.730631276137879,pi/2) = mod(+(1+3897035185165139/2^52)*2.0^(1),pi/2) = 0.58903862254808579922829307350417177314764871585926917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(3.9269808169872413,pi/2) = mod(+(1+4339175044666917/2^52)*2.0^(1),pi/2) = 0.78538816339744809102277071531949143047339334476551917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", +"mod(22.0,pi/2) = mod(+(1+1688849860263936/2^52)*2.0^(4),pi/2) = 0.00885142487144733076149631704347981061981420437425925317538785384528515599653700960375622260518052412496339440702385347034308773314592437792248414310063217784801128108643035226108248763935731548732624899832...", +"mod(333.0,pi/2) = mod(+(1+1354598325420032/2^52)*2.0^(8),pi/2) = 1.56197504627681334219112306401244571719862836592633588714334551152536913680495064474232592640664932788337687284871664873159939369241357455297458244244524210899502716494548602336345749227888525484470275276044...", +"mod(355.0,pi/2) = mod(+(1+1741626418397184/2^52)*2.0^(8),pi/2) = 0.00003014435336405372129768941617408571985787061304222983126106921674608965838315503206473634077131801726622399909934887839555912078420781503438688148163372811789639468094711507176015760676809286683801954435...", +"mod(103993.0,pi/2) = mod(+(1+2642744916836352/2^52)*2.0^(16),pi/2) = 1.57077719745911702881004837353527874739712658493466699787157772281522731705283191410522893791187418892511428058572652122310265696140225654301555183508229071942077441178204362431742351345516837196140445971348...", +"mod(104348.0,pi/2) = mod(+(1+2667140331077632/2^52)*2.0^(16),pi/2) = 0.00001101501758446330002437131170139101839975586015631721536649587806520356811056982327626158158697295130646132818471677795129377741117324218725901249968388881352875511202147883640384875046198736305149704344...", +"mod(208341.0,pi/2) = mod(+(1+2654942623956992/2^52)*2.0^(17),pi/2) = 1.57078821247670149211007274484698013841552634079482331508694421869329252062094248392850519949346116187642074191391123800105395073881342978520281084758197460823430316689406510315382736220563035932445595675693...", +"mod(312689.0,pi/2) = mod(+(1+868356487905280/2^52)*2.0^(18),pi/2) = 2.90069938933617877542451893008733534139696742672181483841841744952104594855443776404840398960083665315998545480145545832221144931191152739015601741793832268987065511732143745138864461786922231647158597... × 10^-6", +"mod(833719.0,pi/2) = mod(+(1+2657992050737152/2^52)*2.0^(19),pi/2) = 1.57079401387548016446762359388484031308620913472967675871662105552819156271283959280403329630144036354972706188482084091197059516171205360825759115961681048487968290820429974602873013949486609776908889992887...", +"mod(1.146408e6,pi/2) = mod(+(1+420185240502272/2^52)*2.0^(20),pi/2) = 5.87779972881415077326764018958322965832009550570043987177791732880615683647927779932034371430395306178613634489043881995068386074403922301611569987864477230727508447806913401705828009489526214389300436... × 10^-7", +"mod(4.272943e6,pi/2) = mod(+(1+84437983297536/2^52)*2.0^(22),pi/2) = 1.57079577721539880871285557417689718805510663075832846884858258890339020455989053658737309240455465473564559772572430804361658036687027682002449599432677407831137509072964316676893525697889456634773206783018...", +"mod(5.419351e6,pi/2) = mod(+(1+1315384200265728/2^52)*2.0^(22),pi/2) = 3.82004750708966112093011647042794877630803261284050974705412148820324696852011356117678675511398777330827176437639516531304810601080841179018325213840634637668871217131295571404954295784087554749162140... × 10^-8", +"mod(8.0143857e7,pi/2) = mod(+(1+874763572477952/2^52)*2.0^(26),pi/2) = 1.57079631202204980126541250439320304796793531388289426651994717648039855301446612940327165715470037069393386088377132073893972419360511833320214661998207345519986782714934715058273522391490866407030871665717...", +"mod(1.65707065e8,pi/2) = mod(+(1+1056606817091584/2^52)*2.0^(27),pi/2) = 8.65478143496479283480806791601818899147100884047004723119419558177519294537964410073515122454559736833697797859473725690814071454276305173366818717701291531848387749318946794370229795161899094380176246... × 10^-9", +"mod(2.45850922e8,pi/2) = mod(+(1+3745788417015808/2^52)*2.0^(27),pi/2) = 1.57079632067683123623020533920127096398612430535390310698999440767459413478965907478291575788985159523953122922074929933367698110174583287596519835365026063221278314563322464377220316761720661568929966045894...", +"mod(4.11557987e8,pi/2) = mod(+(1+2401197617053696/2^52)*2.0^(28),pi/2) = 2.53671605196367648236958743790572859713735903697256934271488151342174752084854244595394428579405455430108612460486731570511125630286557038325420725050055641276613287640889128900803008984309962204629913... × 10^-9", +"mod(1.068966896e9,pi/2) = mod(+(1+4463544628150272/2^52)*2.0^(29),pi/2) = 1.57079632575026334015755830394044583979758149962862118093513309310435716163315411648000064979774016682764033782292154854341161251196834548169633912015867513321389597116549039658998574563326679537549890455154...", +"mod(2.549491779e9,pi/2) = mod(+(1+843072155942912/2^52)*2.0^(31),pi/2) = 4.47449493816149706970976233303722197019495577867890936615779430401846755180508920207307551467187143433646915044596696119497365034532889215443076399478064252395175148483303135651614725663715466720569020... × 10^-10", +"mod(6.167950454e9,pi/2) = mod(+(1+1963965187883008/2^52)*2.0^(32),pi/2) = 1.57079632664516232778985771788239830640502589366761233667091496633591602243684762684101849021235526976201462469021537863260500475096307555076211755104482793217002447595584069355659201693649624670292983799267...", +"mod(1.4885392687e10,pi/2) = mod(+(1+3300633133711360/2^52)*2.0^(33),pi/2) = 1.47980910933221759456269961916604584979614430234776276979795068989333010234511075289901023009068306300795365662712861011872933904331764909404251146367829101604918014490927524901658264139193178277114987... × 10^-10", +"mod(2.1053343141e10,pi/2) = mod(+(1+1015407956983808/2^52)*2.0^(34),pi/2) = 1.57079632679314323872307947733866826832163047864722676690569124331571109142618063707552956550225629277108293099101074429531786576283600945509388246044907907853785357756075870804751954183815451084212301626979...", +"mod(1.783366216531e12,pi/2) = mod(+(1+2801068395540480/2^52)*2.0^(40),pi/2) = 6.96948240875758165283364652450017592218369365167838571237684767728582201531913110512760529814875987841007291472111488973274399752796445730686810635597303227231604049063965142781067801484038929704503126... × 10^-13", +"mod(3.587785776203e12,pi/2) = mod(+(1+2844185642293248/2^52)*2.0^(41),pi/2) = 1.57079632679453713520483099366923499762653051383166350563602692045818646096163780147859339172328181383071268296669275887826208874078255825459947535191045269980904818401522191614564747212371664644509109412920...", +"mod(5.371151992734e12,pi/2) = mod(+(1+996460013189120/2^52)*2.0^(42),pi/2) = 3.37464214385060194766920180395831736328964513722462875515942586261884366107892162736040369453515697892612846187277924980541538489592093576898951719503435891484259641931614955023236781384150844501479806... × 10^-13", +"mod(8.958937768937e12,pi/2) = mod(+(1+83376510325248/2^52)*2.0^(43),pi/2) = 1.57079632679487459941921605386400191780692634556799247014974938333370240354789968584470128388601785420016619866458537172444936666576309979308906744548735165152855161990670617578757908707873988322647524497370...", +"mod(1.39755218526789e14,pi/2) = mod(+(1+4440734358344000/2^52)*2.0^(46),pi/2) = 7.16703280049355852405580552051994292235944787877057242894865818968232636596038712584350583584681705588885972394333979767169688540821492356534377064696422753798816392058646400432320064809223397832709837... × 10^-15", +"mod(4.28224593349304e14,pi/2) = mod(+(1+2347993866218368/2^52)*2.0^(48),pi/2) = 1.57079632679489610051761753453957408522348790539675954849338569505098924952246873282379916504739538471767373911575303830362119668515611488374529209025804768284049251258932014027934084647075285282841952167563...", +"mod(5.706674932067741e15,pi/2) = mod(+(1+1203075304697245/2^52)*2.0^(52),pi/2) = 4.23754646451256218416429262194162608653524752956234482551589924717953528741279504902951631892985510393600689510284748380679359369235443057957270202960326099424609213900534623202922619105230013018255129... × 10^-16", +"mod(6.134899525417045e15,pi/2) = mod(+(1+1631299898046549/2^52)*2.0^(52),pi/2) = 1.57079632679489652427226398579579250165275009955936820201813865128547180111239345077732790632690028766930563210126343190431070696990449556310466132570110564011069547291541956488855474700537605575103862690565..." +] + + + +function testModPi() + for divisorStr in ["2pi","pi","pi/2"] + numbersRegEx = r"[^(]*\(([^,]*),[^(]*\(([^,]*),[^=]*= ([0-9]*.[0-9]+)[^^]*\^?(-?[0-9]+)?" + xDivisor = eval(parse(divisorStr)) + tol = eps(Float64) * xDivisor + + normalizedDivisorStr = replace(divisorStr,"/","o") # 2pi, pi, pio2 + solnList = eval(parse("mod" * normalizedDivisorStr * "Solns")) # see below: mod2piSolns, modpiSolns, modpio2Solns + modFn = eval(parse("mod" * normalizedDivisorStr)) + + print("Testing mod"*normalizedDivisorStr, " with ", length(solnList), " instances... ") + errsNew, errsOld = Array(Float64,0), Array(Float64,0) + for testCase in solnList + decStr, exactStr, solnSignificand, solnExponent = match(numbersRegEx,testCase).captures + solnStr = solnExponent == nothing ? solnSignificand : string(solnSignificand, "e", solnExponent) + # print(lpad(decStr,20," "),": ") + xDec = eval(parse(convert(ASCIIString,decStr))) + xExact = eval(parse(convert(ASCIIString,exactStr))) + xSoln = eval(parse(convert(ASCIIString,solnStr))) + # 1. want: xDec ≈ xExact (dfference of the original x in different representations (decimal vs exact)) + # (might be off because for some x::Float64, if we have eval(parse(repr(x))) != x) + # 2. want: xNew := modFn(xExact) ≈ xSoln <--- this is the crucial bit, xNew close to xSoln + # 3. know: xOld := mod(xExact,xDivisor) might be quite a bit off from xSoln - that's expected + xOld = mod(xExact,xDivisor) + xNew = modFn(xExact) + + reprDiff = abs(xDec - xExact) # should be zero + newDiff = abs(xNew - xSoln) # should be zero, ideally (our new function) + oldDiff = abs(xOld - xSoln) # should be zero in a perfect world, but often bigger due to cancellation + oldDiff = min(oldDiff, abs(xDivisor - oldDiff)) # we are being generous here: + # if xOld happens to end up "on the wrong side of 0", ie + # if xSoln = 3.14 (correct), but xOld reports 0.01, + # we don't take the long way around the circle of 3.14 - 0.01, but the short way of 3.1415.. - (3.14 - 0.1) + # if reprDiff == zero(reprDiff) + # print("Repr ok ") + # else print("Repr ERR ") end + # if abs(newDiff) <= tol && abs(newDiff) <= abs(oldDiff) + # print("new ok ") + # else print("new ERR ") end + push!(errsNew,abs(newDiff)) + push!(errsOld,abs(oldDiff)) + # println("RepErr $(reprDiff) NewErr $(newDiff) OldErr $(oldDiff)") + end + sort!(errsNew) + sort!(errsOld) + totalErrNew = sum(errsNew) + totalErrOld = sum(errsOld) + @test_approx_eq totalErrNew 0.0 + println("Total err = $totalErrNew (new), $totalErrOld (old).") + end +end + + +function testModPiPerformance() + N, runs = 10000, 10 + for divisorStr in ["2pi","pi","pi/2"] + xDivisor = eval(parse(divisorStr)) + normalizedDivisorStr = replace(divisorStr,"/","o") # 2pi, pi, pio2 + modFn = eval(parse("mod" * normalizedDivisorStr)) + + newTimes, oldTimes = Array(Float64,0), Array(Float64,0) + println("Speed: ") + for k = 1:runs + testCases = vcat(repmat(allTestCases(),N),linspace(-1e30,1e30,100*N) .* randn(100*N)) + oldTime = @elapsed for tc in testCases x = mod(tc,pi) end + newTime = @elapsed for tc in testCases x = modFn(tc) end + push!(oldTimes, oldTime) + push!(newTimes, newTime) + println("Items: $(length(testCases)) NewTime: $newTime, OldTime: $oldTime, Ratio: $(newTime/oldTime)") + end + println("Averages:") + println("Items: $(runs) NewTime: $(mean(newTimes)), OldTime: $(mean(oldTimes)), Ratio: $(sum(newTimes)/sum(oldTimes))") + end +end + + +# NOTE: this function used only for timing currently, all testcases are hardcoded +function allTestCases() # for modpi + deltaPi = 0.00001 + pips = [π/16*k + deltaPi for k in [-20:20]] # multiples of pi/16 plus a bit + pims = [π/16*k - deltaPi for k in [-20:20]] # multiples of pi/16 minus a bit + + # numerators of continuous fraction approximations to pi + # see http://oeis.org/A002485 + # (reason: for max cancellation, we want x = k*pi + eps for small eps, so x/k ≈ pi) + contFractionNumerators = [22, 333, 355, 103993, 104348, 208341, 312689, 833719, 1146408, + 4272943, 5419351, 80143857, 165707065, 245850922, 411557987, 1068966896, 2549491779, 6167950454, + 14885392687, 21053343141, 1783366216531, 3587785776203, 5371151992734, 8958937768937, 139755218526789, + 428224593349304, 5706674932067741, 6134899525417045 ] + # note: these numerators below are too big to represent as a Float64 exactly + # 30246273033735921, 66627445592888887, 430010946591069243, 2646693125139304345 + # (all natural numbers <= 9007199254740992 can be represented as a Float64 exactly) + closeToPi = 3.14159265359 + + ΓΓ = 6411027962775774 / 2^47 + # from [2], section 1.2: + # the Float64 greater than 8, and less than 2**63 − 1 closest to a multiple of π/4 is + # Γ = 6411027962775774 / 2^48 + # Gamma mod pi/4 should be ε ≈ 3.9405531196482 × 10^−19 + # Wolfram Alpha: mod( 6411027962775774 * 2^(-48) , pi/4) + # = 3.094903182941788500075335732804827979316517057683310544... × 10^-19 + # we take twice Γ, as we want to be close to pi/2, not pi/4 + # ΓΓ = 2*Γ + + return vcat([-pi/2, pi/2, -pi, pi, 2pi, -2pi, ΓΓ,closeToPi,-closeToPi],pips,pims,contFractionNumerators) +end + + + + +testModPi() +@test_approx_eq mod2pi(355) 3.1416227979431572 +@test_approx_eq mod2pi(355.0) 3.1416227979431572 +@test mod2pi(2^60) == mod2pi(2.0^60) +@test_throws mod2pi(2^60-1) + + +@test_approx_eq mod(355,pi) 3.014435336405372e-5 +@test_approx_eq mod(355.0,pi) 3.014435336405372e-5 +@test_approx_eq modpi(355) 3.014435336405372e-5 +@test_approx_eq modpi(355.0) 3.014435336405372e-5 +@test modpi(2^60) == modpi(2.0^60) +@test_throws mod2pi(2^60-1) + +@test_approx_eq modpio2(355) 3.014435336405372e-5 +@test_approx_eq modpio2(355.0) 3.014435336405372e-5 + diff --git a/test/runtests.jl b/test/runtests.jl index 297762c186572..8ea8272cbe652 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,8 @@ testnames = ["core", "keywordargs", "numbers", "strings", "unicode", "arpack", "file", "suitesparse", "version", "resolve", "pollfd", "mpfr", "broadcast", "complex", "socket", "floatapprox", "readdlm", "regex", "float16", - "combinatorics", "sysinfo", "rounding", "ranges"] + "combinatorics", "sysinfo", "rounding", "ranges", + "math-modpi"] tests = ARGS==["all"] ? testnames : ARGS From d5fda9be2afc73535d069023941ad056a1017965 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Sat, 16 Nov 2013 01:40:33 -0500 Subject: [PATCH 07/11] more tests, fix typos (and that's why we have tests...) --- base/constants.jl | 1 + base/math.jl | 6 +++--- test/math-modpi.jl | 27 +++++++++++++++++---------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/base/constants.jl b/base/constants.jl index e57b53654bb7f..1628742f75798 100644 --- a/base/constants.jl +++ b/base/constants.jl @@ -89,6 +89,7 @@ end 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: diff --git a/base/math.jl b/base/math.jl index baefc3fee24ab..8de777f8de13d 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1479,7 +1479,7 @@ function modpio2(x::Float64) end end -mod2pi(x::Float32)= Float32(mod2pi(Float64(x))) +mod2pi(x::Float32)= float32(mod2pi(float64(x))) mod2pi(x::Int32) = mod2pi(float64(x)) function mod2pi(x::Int64) fx = float64(x) @@ -1487,7 +1487,7 @@ function mod2pi(x::Int64) mod2pi(fx) end -modpi(x::Float32) = Float32(modpi(Float64(x))) +modpi(x::Float32) = float32(modpi(float64(x))) modpi(x::Int32) = modpi(float64(x)) function modpi(x::Int64) fx = float64(x) @@ -1495,7 +1495,7 @@ function modpi(x::Int64) modpi(fx) end -modpio2(x::Float32)= Float32(modpi2(Float64(x))) +modpio2(x::Float32)= float32(modpio2(float64(x))) modpio2(x::Int32) = modpio2(float64(x)) function modpio2(x::Int64) fx = float64(x) diff --git a/test/math-modpi.jl b/test/math-modpi.jl index f02fdc76e502a..b0aefc52a9983 100644 --- a/test/math-modpi.jl +++ b/test/math-modpi.jl @@ -504,19 +504,26 @@ end testModPi() -@test_approx_eq mod2pi(355) 3.1416227979431572 -@test_approx_eq mod2pi(355.0) 3.1416227979431572 +@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) -@test_approx_eq mod(355,pi) 3.014435336405372e-5 -@test_approx_eq mod(355.0,pi) 3.014435336405372e-5 -@test_approx_eq modpi(355) 3.014435336405372e-5 -@test_approx_eq modpi(355.0) 3.014435336405372e-5 +@test_approx_eq mod(355,pi) 3.014435336405372e-5 +@test_approx_eq mod(int32(355),pi) 3.014435336405372e-5 +@test_approx_eq mod(355.0,pi) 3.014435336405372e-5 +@test_approx_eq mod(355.0f0,pi) 3.0144354f-5 +@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 mod2pi(2^60-1) - -@test_approx_eq modpio2(355) 3.014435336405372e-5 -@test_approx_eq modpio2(355.0) 3.014435336405372e-5 +@test_throws modpi(2^60-1) +@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 From 40aca0023c8b761d486ea786d10c949b33b9839e Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Sat, 16 Nov 2013 01:56:25 -0500 Subject: [PATCH 08/11] specify libm library when calling rem_pio2 --- base/math.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/math.jl b/base/math.jl index 8de777f8de13d..a3b84fff58923 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1374,7 +1374,7 @@ function ieee754_rem_pio2(x::Float64) # https://github.com/JuliaLang/openlibm/blob/master/src/e_rem_pio2.c?source=c y = [0.0,0.0] - n = ccall(:__ieee754_rem_pio2, Cint, (Float64,Ptr{Float64}),x,y) + n = ccall((:__ieee754_rem_pio2, libm), Cint, (Float64,Ptr{Float64}),x,y) return (n,y) end From 86a6ab47e5531e1a87e60bbaaf9be0c5ddc2b5a8 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Sat, 16 Nov 2013 04:22:31 -0500 Subject: [PATCH 09/11] refactored testcases into one nice little array, no more eval/parse/regex --- test/math-modpi.jl | 646 ++++++++++++--------------------------------- 1 file changed, 174 insertions(+), 472 deletions(-) diff --git a/test/math-modpi.jl b/test/math-modpi.jl index b0aefc52a9983..3e0adf31495c0 100644 --- a/test/math-modpi.jl +++ b/test/math-modpi.jl @@ -15,495 +15,195 @@ # 6.189806365883577000150671465609655958633034115366621088... × 10^-19 - -#### Correct solutions from WolframAlpha (using the middle formula with the exact repr of the Float64) - -## pi -modpiSolns = [ -"mod(-1.5707963267948966,pi) = mod(-(1+2570638124657944/2^52)*2.0^(0),pi) = 1.57079632679489668046366164900741030340188131343760582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(1.5707963267948966,pi) = mod(+(1+2570638124657944/2^52)*2.0^(0),pi) = 1.5707963267948965579989817342720925807952880859375", -"mod(-3.141592653589793,pi) = mod(-(1+2570638124657944/2^52)*2.0^(1),pi) = 1.22464679914735317722606593227500105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933... × 10^-16", -"mod(3.141592653589793,pi) = mod(+(1+2570638124657944/2^52)*2.0^(1),pi) = 3.141592653589793115997963468544185161590576171875", -"mod(6.283185307179586,pi) = mod(+(1+2570638124657944/2^52)*2.0^(2),pi) = 3.14159265358979299353328355380886743898398294437489417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(-6.283185307179586,pi) = mod(-(1+2570638124657944/2^52)*2.0^(2),pi) = 2.44929359829470635445213186455000211641949889184615632812572417997256069650684234135964296173026564613294187689219101164463450718816256962234900568205403877042211119289245897909860763928857621951331866... × 10^-16", -"mod(45.553093477052,pi) = mod(+(1+1907428335405278/2^52)*2.0^(5),pi) = 1.57079632679489661985030232822810914211365184624851850635077570769057031199307401920751244521036104824992678881404770694068617546629184875584496828620126435569602256217286070452216497527871463097465249799664...", -"mod(3.14159265359,pi) = mod(+(1+2570638124658410/2^52)*2.0^(1),pi) = 2.06823107110214443817242336338901406144179025055407692183593713791001371965174657882932017851913486717693352906155390449417768274640591871518882549715897298061478894440355377051045069618035571189024334... × 10^-13", -"mod(-3.14159265359,pi) = mod(-(1+2570638124658410/2^52)*2.0^(1),pi) = 3.14159265358958641535553316883568564186083049796896164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.9269808169872418,pi) = mod(-(1+4339175044666918/2^52)*2.0^(1),pi) = 2.35620449019234470335066281789739528427110881828146164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.73063127613788,pi) = mod(-(1+3897035185165141/2^52)*2.0^(1),pi) = 2.55255403104170655105593060965009877214418621085958664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.5342817352885176,pi) = mod(-(1+3454895325663363/2^52)*2.0^(1),pi) = 2.74890357189106884285040825146541842946993083976583664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.337932194439156,pi) = mod(-(1+3012755466161586/2^52)*2.0^(1),pi) = 2.94525311274043069055567604321812191734300823234396164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.1415826535897935,pi) = mod(-(1+2570615606659808/2^52)*2.0^(1),pi) = 9.9999999997438875103017539386904715834618751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288... × 10^-6", -"mod(-2.9452331127404316,pi) = mod(-(1+2128475747158031/2^52)*2.0^(1),pi) = 0.19635954084936159159277809350664217834466085445323082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.7488835718910694,pi) = mod(-(1+1686335887656253/2^52)*2.0^(1),pi) = 0.39270908169872388338725573532196183567040548335948082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.5525340310417075,pi) = mod(-(1+1244196028154476/2^52)*2.0^(1),pi) = 0.58905862254808573109252352707466532354348287593760582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.356184490192345,pi) = mod(-(1+802056168652698/2^52)*2.0^(1),pi) = 0.78540816339744802288700116888998498086922750484385582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.1598349493429834,pi) = mod(-(1+359916309150921/2^52)*2.0^(1),pi) = 0.98175770424680987059226896064268846874230489742198082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.9634854084936209,pi) = mod(-(1+4339152526668781/2^52)*2.0^(0),pi) = 1.17810724509617238443135152748931621079438314449229332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.7671358676442588,pi) = mod(-(1+3454872807665226/2^52)*2.0^(0),pi) = 1.37445678594553445418122424427332778339379415523448082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.5707863267948967,pi) = mod(-(1+2570593088661671/2^52)*2.0^(0),pi) = 1.57080632679489652393109696105733935599320516597666832097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.3744367859455346,pi) = mod(-(1+1686313369658116/2^52)*2.0^(0),pi) = 1.76715586764425859368096967784135092859261617671885582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.1780872450961726,pi) = mod(-(1+802033650654561/2^52)*2.0^(0),pi) = 1.96350540849362066343084239462536250119202718746104332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.9817377042468104,pi) = mod(-(1+4339107490672507/2^52)*2.0^(-1),pi) = 2.15985494934298284420301757392502811615460500728526207097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.7853881633974483,pi) = mod(-(1+2570548052665397/2^52)*2.0^(-1),pi) = 2.35620449019234491395289029070903968875401601802744957097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.5890386225480863,pi) = mod(-(1+801988614658287/2^52)*2.0^(-1),pi) = 2.55255403104170698370276300749305126135342702876963707097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.3926890816987242,pi) = mod(-(1+2570457980672850/2^52)*2.0^(-2),pi) = 2.74890357189106905345263572427706283395283803951182457097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.1963395408493621,pi) = mod(-(1+2570277836687755/2^52)*2.0^(-3),pi) = 2.94525311274043115095808405668998791714304075252451988347494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(1.0e-5,pi) = mod(+(1+1399358476216561/2^52)*2.0^(-17),pi) = 0.000010000000000000000818030539140313095458623138256371021270751953125", -"mod(0.19635954084936205,pi) = mod(+(1+2570998412628133/2^52)*2.0^(-3),pi) = 0.1963595408493620519951861069785081781446933746337890625", -"mod(0.3927090816987241,pi) = mod(+(1+2570818268643038/2^52)*2.0^(-2),pi) = 0.39270908169872409398948320813360624015331268310546875", -"mod(0.5890586225480862,pi) = mod(+(1+802168758643381/2^52)*2.0^(-1),pi) = 0.58905862254808616373935592491761781275272369384765625", -"mod(0.7854081633974482,pi) = mod(+(1+2570728196650491/2^52)*2.0^(-1),pi) = 0.78540816339744823348922864170162938535213470458984375", -"mod(0.9817577042468103,pi) = mod(+(1+4339287634657601/2^52)*2.0^(-1),pi) = 0.98175770424681030323910135848564095795154571533203125", -"mod(1.1781072450961723,pi) = mod(+(1+802123722647107/2^52)*2.0^(0),pi) = 1.1781072450961722619666716127539984881877899169921875", -"mod(1.3744567859455343,pi) = mod(+(1+1686403441650662/2^52)*2.0^(0),pi) = 1.374456785945534331716544329538010060787200927734375", -"mod(1.5708063267948964,pi) = mod(+(1+2570683160654217/2^52)*2.0^(0),pi) = 1.5708063267948964014664170463220216333866119384765625", -"mod(1.7671558676442585,pi) = mod(+(1+3454962879657772/2^52)*2.0^(0),pi) = 1.76715586764425847121628976310603320598602294921875", -"mod(1.9635054084936205,pi) = mod(+(1+4339242598661327/2^52)*2.0^(0),pi) = 1.9635054084936205409661624798900447785854339599609375", -"mod(2.159854949342982,pi) = mod(+(1+359961345147192/2^52)*2.0^(1),pi) = 2.159854949342982166626825346611440181732177734375", -"mod(2.3562044901923445,pi) = mod(+(1+802101204648970/2^52)*2.0^(1),pi) = 2.35620449019234445842130298842675983905792236328125", -"mod(2.5525540310417063,pi) = mod(+(1+1244241064150747/2^52)*2.0^(1),pi) = 2.552554031041706306126570780179463326930999755859375", -"mod(2.7489035718910686,pi) = mod(+(1+1686380923652525/2^52)*2.0^(1),pi) = 2.748903571891068597921048421994782984256744384765625", -"mod(2.9452531127404304,pi) = mod(+(1+2128520783154302/2^52)*2.0^(1),pi) = 2.94525311274043044562631621374748647212982177734375", -"mod(3.1416026535897927,pi) = mod(+(1+2570660642656080/2^52)*2.0^(1),pi) = 9.9999999994989581504722833032452583970068748941790250554076921835937137910013719651746578829320178519134867176933529061553904494177682746405918715188825497158972980614788944403553770510450696180355712... × 10^-6", -"mod(3.3379521944391546,pi) = mod(+(1+3012800502157857/2^52)*2.0^(1),pi) = 0.19635954084936134666341826403600673313147439945301917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.534301735288517,pi) = mod(+(1+3454940361659635/2^52)*2.0^(1),pi) = 0.39270908169872363845789590585132639045721902835926917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.7306512761378787,pi) = mod(+(1+3897080221161412/2^52)*2.0^(1),pi) = 0.58905862254808548616316369760402987833029642093739417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.927000816987241,pi) = mod(+(1+4339220080663190/2^52)*2.0^(1),pi) = 0.78540816339744777795764133941934953565604104984364417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(-3.9270008169872415,pi) = mod(-(1+4339220080663191/2^52)*2.0^(1),pi) = 2.35618449019234501641579219379753717908846111320333664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.7306512761378796,pi) = mod(-(1+3897080221161414/2^52)*2.0^(1),pi) = 2.55253403104170686412105998555024066696153850578146164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.5343017352885173,pi) = mod(-(1+3454940361659636/2^52)*2.0^(1),pi) = 2.74888357189106915591553762736556032428728313468771164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.3379521944391555,pi) = mod(-(1+3012800502157859/2^52)*2.0^(1),pi) = 2.94523311274043100362080541911826381216036052726583664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.141602653589793,pi) = mod(-(1+2570660642656081/2^52)*2.0^(1),pi) = 3.14158265358979329541528306093358346948610515617208664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.9452531127404313,pi) = mod(-(1+2128520783154304/2^52)*2.0^(1),pi) = 0.19633954084936190465790746940678407316201314937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.748903571891069,pi) = mod(-(1+1686380923652526/2^52)*2.0^(1),pi) = 0.39268908169872419645238511122210373048775777828135582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.552554031041707,pi) = mod(-(1+1244241064150749/2^52)*2.0^(1),pi) = 0.58903862254808604415765290297480721836083517085948082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.356204490192345,pi) = mod(-(1+802101204648971/2^52)*2.0^(1),pi) = 0.78538816339744833595213054479012687568657979976573082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.159854949342983,pi) = mod(-(1+359961345147194/2^52)*2.0^(1),pi) = 0.98173770424681018365739833654283036355965719234385582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.9635054084936208,pi) = mod(-(1+4339242598661328/2^52)*2.0^(0),pi) = 1.17808724509617247545187597835815002088540182125010582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.7671558676442587,pi) = mod(-(1+3454962879657773/2^52)*2.0^(0),pi) = 1.37443678594553454520174869514216159348481283199229332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.5708063267948966,pi) = mod(-(1+2570683160654218/2^52)*2.0^(0),pi) = 1.57078632679489661495162141192617316608422384273448082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.3744567859455346,pi) = mod(-(1+1686403441650663/2^52)*2.0^(0),pi) = 1.76713586764425868470149412871018473868363485347666832097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.1781072450961725,pi) = mod(-(1+802123722647108/2^52)*2.0^(0),pi) = 1.96348540849362075445136684549419631128304586421885582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.9817577042468104,pi) = mod(-(1+4339287634657602/2^52)*2.0^(-1),pi) = 2.15983494934298282420123956227820788388245687496104332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.7854081633974483,pi) = mod(-(1+2570728196650492/2^52)*2.0^(-1),pi) = 2.35618449019234489395111227906221945648186788570323082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.5890586225480863,pi) = mod(-(1+802168758643382/2^52)*2.0^(-1),pi) = 2.55253403104170696370098499584623102908127889644541832097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.39270908169872415,pi) = mod(-(1+2570818268643039/2^52)*2.0^(-2),pi) = 2.74888357189106908896200894388806962286227331172862144597494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-0.19635954084936208,pi) = mod(-(1+2570998412628134/2^52)*2.0^(-3),pi) = 2.94523311274043115871188166067208119546168432247080894597494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.0e-5,pi) = mod(-(1+1399358476216561/2^52)*2.0^(-17),pi) = 3.14158265358979323846182535274036257110171077623684944995367384035469140628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(0.19633954084936206,pi) = mod(+(1+2570277836687754/2^52)*2.0^(-3),pi) = 0.196339540849362059748983710960601456463336944580078125", -"mod(0.39268908169872413,pi) = mod(+(1+2570457980672849/2^52)*2.0^(-2),pi) = 0.392689081698724129498856427744613029062747955322265625", -"mod(0.5890386225480861,pi) = mod(+(1+801988614658286/2^52)*2.0^(-1),pi) = 0.5890386225480861437375779132707975804805755615234375", -"mod(0.7853881633974482,pi) = mod(+(1+2570548052665396/2^52)*2.0^(-1),pi) = 0.785388163397448213487450630054809153079986572265625", -"mod(0.9817377042468103,pi) = mod(+(1+4339107490672506/2^52)*2.0^(-1),pi) = 0.9817377042468102832373233468388207256793975830078125", -"mod(1.1780872450961724,pi) = mod(+(1+802033650654560/2^52)*2.0^(0),pi) = 1.17808724509617235298719606362283229827880859375", -"mod(1.3744367859455344,pi) = mod(+(1+1686313369658115/2^52)*2.0^(0),pi) = 1.3744367859455344227370687804068438708782196044921875", -"mod(1.5707863267948965,pi) = mod(+(1+2570593088661670/2^52)*2.0^(0),pi) = 1.570786326794896492486941497190855443477630615234375", -"mod(1.7671358676442586,pi) = mod(+(1+3454872807665225/2^52)*2.0^(0),pi) = 1.7671358676442585622368142139748670160770416259765625", -"mod(1.9634854084936206,pi) = mod(+(1+4339152526668780/2^52)*2.0^(0),pi) = 1.96348540849362063198668693075887858867645263671875", -"mod(2.1598349493429825,pi) = mod(+(1+359916309150919/2^52)*2.0^(1),pi) = 2.159834949342982479691954722511582076549530029296875", -"mod(2.3561844901923448,pi) = mod(+(1+802056168652697/2^52)*2.0^(1),pi) = 2.356184490192344771486432364326901733875274658203125", -"mod(2.5525340310417066,pi) = mod(+(1+1244196028154474/2^52)*2.0^(1),pi) = 2.55253403104170661919170015607960522174835205078125", -"mod(2.748883571891069,pi) = mod(+(1+1686335887656252/2^52)*2.0^(1),pi) = 2.7488835718910689109861777978949248790740966796875", -"mod(2.9452331127404308,pi) = mod(+(1+2128475747158029/2^52)*2.0^(1),pi) = 2.945233112740430758691445589647628366947174072265625", -"mod(3.141582653589793,pi) = mod(+(1+2570615606659807/2^52)*2.0^(1),pi) = 3.141582653589793050485923231462948024272918701171875", -"mod(3.337932194439155,pi) = mod(+(1+3012755466161584/2^52)*2.0^(1),pi) = 0.19633954084936165972854763993614862794882669437489417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.534281735288517,pi) = mod(+(1+3454895325663362/2^52)*2.0^(1),pi) = 0.39268908169872395152302528175146828527457132328114417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.730631276137879,pi) = mod(+(1+3897035185165139/2^52)*2.0^(1),pi) = 0.58903862254808579922829307350417177314764871585926917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.9269808169872413,pi) = mod(+(1+4339175044666917/2^52)*2.0^(1),pi) = 0.78538816339744809102277071531949143047339334476551917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(22.0,pi) = mod(+(1+1688849860263936/2^52)*2.0^(4),pi) = 0.00885142487144733076149631704347981061981420437425925317538785384528515599653700960375622260518052412496339440702385347034308773314592437792248414310063217784801128108643035226108248763935731548732624899832...", -"mod(333.0,pi) = mod(+(1+1354598325420032/2^52)*2.0^(8),pi) = 3.13277137307170996142244475565219715929721306561388879763081780767927733994805514405634333907770786187445091610535780205514631599718886566883726214650948266772016921629645528391623731459035973230989373497484...", -"mod(355.0,pi) = mod(+(1+1741626418397184/2^52)*2.0^(8),pi) = 0.00003014435336405372129768941617408571985787061304222983126106921674608965838315503206473634077131801726622399909934887839555912078420781503438688148163372811789639468094711507176015760676809286683801954435...", -"mod(103993.0,pi) = mod(+(1+2642744916836352/2^52)*2.0^(16),pi) = 3.14157352425401364804137006517503018949571128462221990835905001896913552019593641341924635058293272291618832384236767454664957926617754765887823153914653127814591646313301288487020333576664284942659544192789...", -"mod(104348.0,pi) = mod(+(1+2667140331077632/2^52)*2.0^(16),pi) = 0.00001101501758446330002437131170139101839975586015631721536649587806520356811056982327626158158697295130646132818471677795129377741117324218725901249968388881352875511202147883640384875046198736305149704344...", -"mod(208341.0,pi) = mod(+(1+2654942623956992/2^52)*2.0^(17),pi) = 3.14158453927159811134139443648673158051411104048237622557441651484720072376404698324252261216451969586749478517055239132460087304358872090106549055164621516695944521824503436370660718451710483678964693897133...", -"mod(312689.0,pi) = mod(+(1+868356487905280/2^52)*2.0^(18),pi) = 2.90069938933617877542451893008733534139696742672181483841841744952104594855443776404840398960083665315998545480145545832221144931191152739015601741793832268987065511732143745138864461786922231647158597... × 10^-6", -"mod(833719.0,pi) = mod(+(1+2657992050737152/2^52)*2.0^(19),pi) = 3.14159034067037678369894528552459175518479383441722966920409335168209976585594409211805070897249889754080110514146199423551751746648734472412027086368105104360482495955526900658150996180634057523427988214327...", -"mod(1.146408e6,pi) = mod(+(1+420185240502272/2^52)*2.0^(20),pi) = 5.87779972881415077326764018958322965832009550570043987177791732880615683647927779932034371430395306178613634489043881995068386074403922301611569987864477230727508447806913401705828009489526214389300436... × 10^-7", -"mod(4.272943e6,pi) = mod(+(1+84437983297536/2^52)*2.0^(22),pi) = 3.14159210401029542794417726581664863015369133044588137933605488505729840770299503590139050507561318872671964098236546136716350267164556793588717569839101463703651714208061242732171507929036904381292305004458...", -"mod(5.419351e6,pi) = mod(+(1+1315384200265728/2^52)*2.0^(22),pi) = 3.82004750708966112093011647042794877630803261284050974705412148820324696852011356117678675511398777330827176437639516531304810601080841179018325213840634637668871217131295571404954295784087554749162140... × 10^-8", -"mod(8.0143857e7,pi) = mod(+(1+874763572477952/2^52)*2.0^(26),pi) = 3.14159263881694642049673419603295449006652001357044717700741947263430675615757062871728906982575890468500790414041247406248664649838040944906482632404631401392500987850031641113551504622638314153549969887158...", -"mod(1.65707065e8,pi) = mod(+(1+1056606817091584/2^52)*2.0^(27),pi) = 8.65478143496479283480806791601818899147100884047004723119419558177519294537964410073515122454559736833697797859473725690814071454276305173366818717701291531848387749318946794370229795161899094380176246... × 10^-9", -"mod(2.45850922e8,pi) = mod(+(1+3745788417015808/2^52)*2.0^(27),pi) = 3.14159264747172785546152703084102240608470900504145601747746670382850233793276357409693317056091012923060527247739045265722390340652112399182787805771450119093792519698419390432498298992868109315449064267334...", -"mod(4.11557987e8,pi) = mod(+(1+2401197617053696/2^52)*2.0^(28),pi) = 2.53671605196367648236958743790572859713735903697256934271488151342174752084854244595394428579405455430108612460486731570511125630286557038325420725050055641276613287640889128900803008984309962204629913... × 10^-9", -"mod(1.068966896e9,pi) = mod(+(1+4463544628150272/2^52)*2.0^(29),pi) = 3.14159265254515995938887999558019728189616619931617409142260538925826536477625861579401806246879870081871438107956270186695853481674363659755901882422291569193903802251645965714276556794474127284068988676594...", -"mod(2.549491779e9,pi) = mod(+(1+843072155942912/2^52)*2.0^(31),pi) = 4.47449493816149706970976233303722197019495577867890936615779430401846755180508920207307551467187143433646915044596696119497365034532889215443076399478064252395175148483303135651614725663715466720569020... × 10^-10", -"mod(6.167950454e9,pi) = mod(+(1+1963965187883008/2^52)*2.0^(32),pi) = 3.14159265344005894702117940952214974850361059335516524715838726248982422557995212615503590288341380375308866794685653195615192705573836666662479725510906849089516652730680995410937183924797072416812082020708...", -"mod(1.4885392687e10,pi) = mod(+(1+3300633133711360/2^52)*2.0^(33),pi) = 1.47980910933221759456269961916604584979614430234776276979795068989333010234511075289901023009068306300795365662712861011872933904331764909404251146367829101604918014490927524901658264139193178277114987... × 10^-10", -"mod(2.1053343141e10,pi) = mod(+(1+1015407956983808/2^52)*2.0^(34),pi) = 3.14159265358803985795440116897841971042021517833477967739316353946961929456928513638954697817331482676215697424765189761886478806761130057095656216451331963726299562891172796860029936414962898830731399848419...", -"mod(1.783366216531e12,pi) = mod(+(1+2801068395540480/2^52)*2.0^(40),pi) = 6.96948240875758165283364652450017592218369365167838571237684767728582201531913110512760529814875987841007291472111488973274399752796445730686810635597303227231604049063965142781067801484038929704503126... × 10^-13", -"mod(3.587785776203e12,pi) = mod(+(1+2844185642293248/2^52)*2.0^(41),pi) = 3.14159265358943375443615268530898643972511521351921641612349921661209466410474230079261080439434034782178672622333391220180901104555784937046215505597469325853419023536619117669842729443519112391028207634360...", -"mod(5.371151992734e12,pi) = mod(+(1+996460013189120/2^52)*2.0^(42),pi) = 3.37464214385060194766920180395831736328964513722462875515942586261884366107892162736040369453515697892612846187277924980541538489592093576898951719503435891484259641931614955023236781384150844501479806... × 10^-13", -"mod(8.958937768937e12,pi) = mod(+(1+83376510325248/2^52)*2.0^(43),pi) = 3.14159265358977121865053774550375335990551104525554538063722167948761060669100418515871869655707638819124024192122652504799628897053839090895174714955159221025369367125767543634035890939021436069166622718810...", -"mod(1.39755218526789e14,pi) = mod(+(1+4440734358344000/2^52)*2.0^(46),pi) = 7.16703280049355852405580552051994292235944787877057242894865818968232636596038712584350583584681705588885972394333979767169688540821492356534377064696422753798816392058646400432320064809223397832709837... × 10^-15", -"mod(4.28224593349304e14,pi) = mod(+(1+2347993866218368/2^52)*2.0^(48),pi) = 3.14159265358979271974893922617932552732207260508431245898085799120489745266557323213781657771845391870874778237239419162716811898993140599960797179432228824156563456394028940083212066878222733029361050389004...", -"mod(5.706674932067741e15,pi) = mod(+(1+1203075304697245/2^52)*2.0^(52),pi) = 4.23754646451256218416429262194162608653524752956234482551589924717953528741279504902951631892985510393600689510284748380679359369235443057957270202960326099424609213900534623202922619105230013018255129... × 10^-16", -"mod(6.134899525417045e15,pi) = mod(+(1+1631299898046549/2^52)*2.0^(52),pi) = 3.14159265358979314350358567743554394375133479924692111250561094743938000425549795009134531899795882166037967535790458522785762927467978667896734102976534619883583752426638882544133456931685053321622960912005..." ] - - - -## 2*pi -mod2piSolns = [ -"mod(-1.5707963267948966,2*pi) = mod(-(1+2570638124657944/2^52)*2^(0),2*pi) = 4.71238898038468991892630503228691318759905071281271164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(1.5707963267948966,2*pi) = mod(+(1+2570638124657944/2^52)*2^(0),2*pi) = 1.5707963267948965579989817342720925807952880859375", -"mod(-3.141592653589793,2*pi) = mod(-(1+2570638124657944/2^52)*2^(1),2*pi) = 3.14159265358979336092732329801482060680376262687521164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(3.141592653589793,2*pi) = mod(+(1+2570638124657944/2^52)*2^(1),2*pi) = 3.141592653589793115997963468544185161590576171875", -"mod(6.283185307179586,2*pi) = mod(+(1+2570638124657944/2^52)*2^(2),2*pi) = 6.28318530717958623199592693708837032318115234375", -"mod(-6.283185307179586,2*pi) = mod(-(1+2570638124657944/2^52)*2^(2),2*pi) = 2.44929359829470635445213186455000211641949889184615632812572417997256069650684234135964296173026564613294187689219101164463450718816256962234900568205403877042211119289245897909860763928857621951331866... × 10^-16", -"mod(45.553093477052,2*pi) = mod(+(1+1907428335405278/2^52)*2.0^(5),2*pi) = 1.57079632679489661985030232822810914211365184624851850635077570769057031199307401920751244521036104824992678881404770694068617546629184875584496828620126435569602256217286070452216497527871463097465249799664...", -"mod(3.14159265359,2*pi) = mod(+(1+2570638124658410/2^52)*2.0^(1),2*pi) = 3.14159265359000006156975359772332012653350830078125", -"mod(-3.14159265359,2*pi) = mod(-(1+2570638124658410/2^52)*2.0^(1),2*pi) = 3.14159265358958641535553316883568564186083049796896164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.9269808169872418,2*pi) = mod(-(1+4339175044666918/2^52)*2.0^(1),2*pi) = 2.35620449019234470335066281789739528427110881828146164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.73063127613788,2*pi) = mod(-(1+3897035185165141/2^52)*2.0^(1),2*pi) = 2.55255403104170655105593060965009877214418621085958664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.5342817352885176,2*pi) = mod(-(1+3454895325663363/2^52)*2.0^(1),2*pi) = 2.74890357189106884285040825146541842946993083976583664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.337932194439156,2*pi) = mod(-(1+3012755466161586/2^52)*2.0^(1),2*pi) = 2.94525311274043069055567604321812191734300823234396164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.1415826535897935,2*pi) = mod(-(1+2570615606659808/2^52)*2.0^(1),2*pi) = 3.14160265358979298235015368503344157466875286125021164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.9452331127404316,2*pi) = mod(-(1+2128475747158031/2^52)*2.0^(1),2*pi) = 3.33795219443915483005542147678614506254183025382833664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.7488835718910694,2*pi) = mod(-(1+1686335887656253/2^52)*2.0^(1),2*pi) = 3.53430173528851712184989911860146471986757488273458664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.5525340310417075,2*pi) = mod(-(1+1244196028154476/2^52)*2.0^(1),2*pi) = 3.73065127613787896955516691035416820774065227531271164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.356184490192345,2*pi) = mod(-(1+802056168652698/2^52)*2.0^(1),2*pi) = 3.92700081698724126134964455216948786506639690421896164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.1598349493429834,2*pi) = mod(-(1+359916309150921/2^52)*2.0^(1),2*pi) = 4.12335035783660310905491234392219135293947429679708664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.9634854084936209,2*pi) = mod(-(1+4339152526668781/2^52)*2.0^(0),2*pi) = 4.31969989868596562289399491076881909499155254386739914194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.7671358676442588,2*pi) = mod(-(1+3454872807665226/2^52)*2.0^(0),2*pi) = 4.51604943953532769264386762755283066759096355460958664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.5707863267948967,2*pi) = mod(-(1+2570593088661671/2^52)*2.0^(0),2*pi) = 4.71239898038468976239374034433684224019037456535177414194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.3744367859455346,2*pi) = mod(-(1+1686313369658116/2^52)*2.0^(0),2*pi) = 4.90874852123405183214361306112085381278978557609396164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.1780872450961726,2*pi) = mod(-(1+802033650654561/2^52)*2.0^(0),2*pi) = 5.10509806208341390189348577790486538538919658683614914194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.9817377042468104,2*pi) = mod(-(1+4339107490672507/2^52)*2.0^(-1),2*pi) = 5.30144760293277608266566095720453100035177440666036789194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.7853881633974483,2*pi) = mod(-(1+2570548052665397/2^52)*2.0^(-1),2*pi) = 5.49779714378213815241553367398854257295118541740255539194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.5890386225480863,2*pi) = mod(-(1+801988614658287/2^52)*2.0^(-1),2*pi) = 5.69414668463150022216540639077255414555059642814474289194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.3926890816987242,2*pi) = mod(-(1+2570457980672850/2^52)*2.0^(-2),2*pi) = 5.89049622548086229191527910755656571815000743888693039194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.1963395408493621,2*pi) = mod(-(1+2570277836687755/2^52)*2.0^(-3),2*pi) = 6.08684576633022438942072743996949080134021015189962570444988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(1.0e-5,2*pi) = mod(+(1+1399358476216561/2^52)*2.0^(-17),2*pi) = 0.000010000000000000000818030539140313095458623138256371021270751953125", -"mod(0.19635954084936205,2*pi) = mod(+(1+2570998412628133/2^52)*2.0^(-3),2*pi) = 0.1963595408493620519951861069785081781446933746337890625", -"mod(0.3927090816987241,2*pi) = mod(+(1+2570818268643038/2^52)*2.0^(-2),2*pi) = 0.39270908169872409398948320813360624015331268310546875", -"mod(0.5890586225480862,2*pi) = mod(+(1+802168758643381/2^52)*2.0^(-1),2*pi) = 0.58905862254808616373935592491761781275272369384765625", -"mod(0.7854081633974482,2*pi) = mod(+(1+2570728196650491/2^52)*2.0^(-1),2*pi) = 0.78540816339744823348922864170162938535213470458984375", -"mod(0.9817577042468103,2*pi) = mod(+(1+4339287634657601/2^52)*2.0^(-1),2*pi) = 0.98175770424681030323910135848564095795154571533203125", -"mod(1.1781072450961723,2*pi) = mod(+(1+802123722647107/2^52)*2.0^(0),2*pi) = 1.1781072450961722619666716127539984881877899169921875", -"mod(1.3744567859455343,2*pi) = mod(+(1+1686403441650662/2^52)*2.0^(0),2*pi) = 1.374456785945534331716544329538010060787200927734375", -"mod(1.5708063267948964,2*pi) = mod(+(1+2570683160654217/2^52)*2.0^(0),2*pi) = 1.5708063267948964014664170463220216333866119384765625", -"mod(1.7671558676442585,2*pi) = mod(+(1+3454962879657772/2^52)*2.0^(0),2*pi) = 1.76715586764425847121628976310603320598602294921875", -"mod(1.9635054084936205,2*pi) = mod(+(1+4339242598661327/2^52)*2.0^(0),2*pi) = 1.9635054084936205409661624798900447785854339599609375", -"mod(2.159854949342982,2*pi) = mod(+(1+359961345147192/2^52)*2.0^(1),2*pi) = 2.159854949342982166626825346611440181732177734375", -"mod(2.3562044901923445,2*pi) = mod(+(1+802101204648970/2^52)*2.0^(1),2*pi) = 2.35620449019234445842130298842675983905792236328125", -"mod(2.5525540310417063,2*pi) = mod(+(1+1244241064150747/2^52)*2.0^(1),2*pi) = 2.552554031041706306126570780179463326930999755859375", -"mod(2.7489035718910686,2*pi) = mod(+(1+1686380923652525/2^52)*2.0^(1),2*pi) = 2.748903571891068597921048421994782984256744384765625", -"mod(2.9452531127404304,2*pi) = mod(+(1+2128520783154302/2^52)*2.0^(1),2*pi) = 2.94525311274043044562631621374748647212982177734375", -"mod(3.1416026535897927,2*pi) = mod(+(1+2570660642656080/2^52)*2.0^(1),2*pi) = 3.14160265358979273742079385556280612945556640625", -"mod(3.3379521944391546,2*pi) = mod(+(1+3012800502157857/2^52)*2.0^(1),2*pi) = 3.337952194439154585126061647315509617328643798828125", -"mod(3.534301735288517,2*pi) = mod(+(1+3454940361659635/2^52)*2.0^(1),2*pi) = 3.534301735288516876920539289130829274654388427734375", -"mod(3.7306512761378787,2*pi) = mod(+(1+3897080221161412/2^52)*2.0^(1),2*pi) = 3.7306512761378787246258070808835327625274658203125", -"mod(3.927000816987241,2*pi) = mod(+(1+4339220080663190/2^52)*2.0^(1),2*pi) = 3.92700081698724101642028472269885241985321044921875", -"mod(-3.9270008169872415,2*pi) = mod(-(1+4339220080663191/2^52)*2.0^(1),2*pi) = 2.35618449019234501641579219379753717908846111320333664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.7306512761378796,2*pi) = mod(-(1+3897080221161414/2^52)*2.0^(1),2*pi) = 2.55253403104170686412105998555024066696153850578146164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.5343017352885173,2*pi) = mod(-(1+3454940361659636/2^52)*2.0^(1),2*pi) = 2.74888357189106915591553762736556032428728313468771164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.3379521944391555,2*pi) = mod(-(1+3012800502157859/2^52)*2.0^(1),2*pi) = 2.94523311274043100362080541911826381216036052726583664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-3.141602653589793,2*pi) = mod(-(1+2570660642656081/2^52)*2.0^(1),2*pi) = 3.14158265358979329541528306093358346948610515617208664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.9452531127404313,2*pi) = mod(-(1+2128520783154304/2^52)*2.0^(1),2*pi) = 3.33793219443915514312055085268628695735918254875021164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.748903571891069,2*pi) = mod(-(1+1686380923652526/2^52)*2.0^(1),2*pi) = 3.53428173528851743491502849450160661468492717765646164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.552554031041707,2*pi) = mod(-(1+1244241064150749/2^52)*2.0^(1),2*pi) = 3.73063127613787928262029628625431010255800457023458664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.356204490192345,2*pi) = mod(-(1+802101204648971/2^52)*2.0^(1),2*pi) = 3.92698081698724157441477392806962975988374919914083664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-2.159854949342983,2*pi) = mod(-(1+359961345147194/2^52)*2.0^(1),2*pi) = 4.12333035783660342212004171982233324775682659171896164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.9635054084936208,2*pi) = mod(-(1+4339242598661328/2^52)*2.0^(0),2*pi) = 4.31967989868596571391451936163765290508257122062521164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.7671558676442587,2*pi) = mod(-(1+3454962879657773/2^52)*2.0^(0),2*pi) = 4.51602943953532778366439207842166447768198223136739914194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.5708063267948966,2*pi) = mod(-(1+2570683160654218/2^52)*2.0^(0),2*pi) = 4.71237898038468985341426479520567605028139324210958664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.3744567859455346,2*pi) = mod(-(1+1686403441650663/2^52)*2.0^(0),2*pi) = 4.90872852123405192316413751198968762288080425285177414194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.1781072450961725,2*pi) = mod(-(1+802123722647108/2^52)*2.0^(0),2*pi) = 5.10507806208341399291401022877369919548021526359396164194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.9817577042468104,2*pi) = mod(-(1+4339287634657602/2^52)*2.0^(-1),2*pi) = 5.30142760293277606266388294555771076807962627433614914194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.7854081633974483,2*pi) = mod(-(1+2570728196650492/2^52)*2.0^(-1),2*pi) = 5.49777714378213813241375566234172234067903728507833664194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.5890586225480863,2*pi) = mod(-(1+802168758643382/2^52)*2.0^(-1),2*pi) = 5.69412668463150020216362837912573391327844829582052414194988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.39270908169872415,2*pi) = mod(-(1+2570818268643039/2^52)*2.0^(-2),2*pi) = 5.89047622548086232742465232716757250705944271110372726694988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-0.19635954084936208,2*pi) = mod(-(1+2570998412628134/2^52)*2.0^(-3),2*pi) = 6.08682576633022439717452504395158407965885372184591476694988918461563281257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(-1.0e-5,2*pi) = mod(-(1+1399358476216561/2^52)*2.0^(-17),2*pi) = 6.28317530717958647692446873601986545529888017561195527092861843266250781257241799725606965068423413596429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392885762...", -"mod(0.19633954084936206,2*pi) = mod(+(1+2570277836687754/2^52)*2.0^(-3),2*pi) = 0.196339540849362059748983710960601456463336944580078125", -"mod(0.39268908169872413,2*pi) = mod(+(1+2570457980672849/2^52)*2.0^(-2),2*pi) = 0.392689081698724129498856427744613029062747955322265625", -"mod(0.5890386225480861,2*pi) = mod(+(1+801988614658286/2^52)*2.0^(-1),2*pi) = 0.5890386225480861437375779132707975804805755615234375", -"mod(0.7853881633974482,2*pi) = mod(+(1+2570548052665396/2^52)*2.0^(-1),2*pi) = 0.785388163397448213487450630054809153079986572265625", -"mod(0.9817377042468103,2*pi) = mod(+(1+4339107490672506/2^52)*2.0^(-1),2*pi) = 0.9817377042468102832373233468388207256793975830078125", -"mod(1.1780872450961724,2*pi) = mod(+(1+802033650654560/2^52)*2.0^(0),2*pi) = 1.17808724509617235298719606362283229827880859375", -"mod(1.3744367859455344,2*pi) = mod(+(1+1686313369658115/2^52)*2.0^(0),2*pi) = 1.3744367859455344227370687804068438708782196044921875", -"mod(1.5707863267948965,2*pi) = mod(+(1+2570593088661670/2^52)*2.0^(0),2*pi) = 1.570786326794896492486941497190855443477630615234375", -"mod(1.7671358676442586,2*pi) = mod(+(1+3454872807665225/2^52)*2.0^(0),2*pi) = 1.7671358676442585622368142139748670160770416259765625", -"mod(1.9634854084936206,2*pi) = mod(+(1+4339152526668780/2^52)*2.0^(0),2*pi) = 1.96348540849362063198668693075887858867645263671875", -"mod(2.1598349493429825,2*pi) = mod(+(1+359916309150919/2^52)*2.0^(1),2*pi) = 2.159834949342982479691954722511582076549530029296875", -"mod(2.3561844901923448,2*pi) = mod(+(1+802056168652697/2^52)*2.0^(1),2*pi) = 2.356184490192344771486432364326901733875274658203125", -"mod(2.5525340310417066,2*pi) = mod(+(1+1244196028154474/2^52)*2.0^(1),2*pi) = 2.55253403104170661919170015607960522174835205078125", -"mod(2.748883571891069,2*pi) = mod(+(1+1686335887656252/2^52)*2.0^(1),2*pi) = 2.7488835718910689109861777978949248790740966796875", -"mod(2.9452331127404308,2*pi) = mod(+(1+2128475747158029/2^52)*2.0^(1),2*pi) = 2.945233112740430758691445589647628366947174072265625", -"mod(3.141582653589793,2*pi) = mod(+(1+2570615606659807/2^52)*2.0^(1),2*pi) = 3.141582653589793050485923231462948024272918701171875", -"mod(3.337932194439155,2*pi) = mod(+(1+3012755466161584/2^52)*2.0^(1),2*pi) = 3.33793219443915489819119102321565151214599609375", -"mod(3.534281735288517,2*pi) = mod(+(1+3454895325663362/2^52)*2.0^(1),2*pi) = 3.53428173528851718998566866503097116947174072265625", -"mod(3.730631276137879,2*pi) = mod(+(1+3897035185165139/2^52)*2.0^(1),2*pi) = 3.730631276137879037690936456783674657344818115234375", -"mod(3.9269808169872413,2*pi) = mod(+(1+4339175044666917/2^52)*2.0^(1),2*pi) = 3.926980816987241329485414098598994314670562744140625", -"mod(22.0,2*pi) = mod(+(1+1688849860263936/2^52)*2.0^(4),2*pi) = 3.15044407846124056922413970032298269481698360374936507415033244615310156228274600823179104794729759210711148092030616011743693234269650660964784355122911329529829538378836887336664213226230627041770821342713...", -"mod(333.0,2*pi) = mod(+(1+1354598325420032/2^52)*2.0^(8),2*pi) = 6.27436402666150319988508813893170004349438246498899461860576239998709374623426414268437816441982492985659900261864010870224016060673944790056262155463796378517045331899839380502179695921330868724027569940365...", -"mod(355.0,2*pi) = mod(+(1+1741626418397184/2^52)*2.0^(8),2*pi) = 3.14162279794315729218394107269567696991702726998814805080620566152456249594459215366009956168288838599941431051238165552548940373033479004675974628961011484556818049738288563617731980222971704779721998397317...", -"mod(103993.0,2*pi) = mod(+(1+2642744916836352/2^52)*2.0^(16),2*pi) = 6.28316617784380688650401344845453307369288068399732572933399461127695192648214541204728117592504979089833641035564998119374342387572812989060359094727501239559620056583495140597576298038959180435697740635670...", -"mod(104348.0,2*pi) = mod(+(1+2667140331077632/2^52)*2.0^(16),2*pi) = 3.14160366860737770176266775459120427521556915523526213819031108818588160985431956845131108692370404093345454784146702342504513838696175547391261842062816500626381285781395999994196349337341094229343346147225...", -"mod(208341.0,2*pi) = mod(+(1+2654942623956992/2^52)*2.0^(17),2*pi) = 3.14158453927159811134139443648673158051411104048237622557441651484720072376404698324252261216451969586749478517055239132460087304358872090106549055164621516695944521824503436370660718451710483678964693897133...", -"mod(312689.0,2*pi) = mod(+(1+868356487905280/2^52)*2.0^(18),2*pi) = 2.90069938933617877542451893008733534139696742672181483841841744952104594855443776404840398960083665315998545480145545832221144931191152739015601741793832268987065511732143745138864461786922231647158597... × 10^-6", -"mod(833719.0,2*pi) = mod(+(1+2657992050737152/2^52)*2.0^(19),2*pi) = 3.14159034067037678369894528552459175518479383441722966920409335168209976585594409211805070897249889754080110514146199423551751746648734472412027086368105104360482495955526900658150996180634057523427988214327...", -"mod(1.146408e6,2*pi) = mod(+(1+420185240502272/2^52)*2.0^(20),2*pi) = 3.14159324136976611987772071004352184252013523138465639101893177009954928690189264655581475737648849837745426512691679569097583967793665663564766101969846898192751483021038632801896135045095844445659635372924...", -"mod(4.272943e6,2*pi) = mod(+(1+84437983297536/2^52)*2.0^(22),2*pi) = 6.28318475760008866640682064909615151435086072982098720031099947736511481398920403452942533041773025670886772749564776801425734728119615016761253510651949575448680124478255094842727472391331799874330501447339...", -"mod(5.419351e6,2*pi) = mod(+(1+1315384200265728/2^52)*2.0^(22),2*pi) = 3.14159269179026830935925459258066758847665716245543194938004206284903128831867868382917043710998461912202581959599995041104549774003164233980947730996100250151374786958906023423511678511837853333913743934502...", -"mod(8.0143857e7,2*pi) = mod(+(1+874763572477952/2^52)*2.0^(26),2*pi) = 6.28318529240673965895937757931245737426368941294555299798236406494212316244377962734532389516787597266715599065369478070958049110793099168079018573217479513137529398120225493224107469084933209646588166330039...", -"mod(1.65707065e8,2*pi) = mod(+(1+1056606817091584/2^52)*2.0^(27),2*pi) = 3.14159266224457467342743621808757080021535839084611466144499182350201198806140194400767892607726829252774545485026028524183110151769129677448841114179666829446319942118581601429502758832524690654937290823057...", -"mod(2.45850922e8,2*pi) = mod(+(1+3745788417015808/2^52)*2.0^(27),2*pi) = 3.14159264747172785546152703084102240608470900504145601747746670382850233793276357409693317056091012923060527247739045265722390340652112399182787805771450119093792519698419390432498298992868109315449064267334...", -"mod(4.11557987e8,2*pi) = mod(+(1+2401197617053696/2^52)*2.0^(28),2*pi) = 2.53671605196367648236958743790572859713735903697256934271488151342174752084854244595394428579405455430108612460486731570511125630286557038325420725050055641276613287640889128900803008984309962204629913... × 10^-9", -"mod(1.068966896e9,2*pi) = mod(+(1+4463544628150272/2^52)*2.0^(29),2*pi) = 3.14159265254515995938887999558019728189616619931617409142260538925826536477625861579401806246879870081871438107956270186695853481674363659755901882422291569193903802251645965714276556794474127284068988676594...", -"mod(2.549491779e9,2*pi) = mod(+(1+843072155942912/2^52)*2.0^(31),2*pi) = 4.47449493816149706970976233303722197019495577867890936615779430401846755180508920207307551467187143433646915044596696119497365034532889215443076399478064252395175148483303135651614725663715466720569020... × 10^-10", -"mod(6.167950454e9,2*pi) = mod(+(1+1963965187883008/2^52)*2.0^(32),2*pi) = 3.14159265344005894702117940952214974850361059335516524715838726248982422557995212615503590288341380375308866794685653195615192705573836666662479725510906849089516652730680995410937183924797072416812082020708...", -"mod(1.4885392687e10,2*pi) = mod(+(1+3300633133711360/2^52)*2.0^(33),2*pi) = 1.47980910933221759456269961916604584979614430234776276979795068989333010234511075289901023009068306300795365662712861011872933904331764909404251146367829101604918014490927524901658264139193178277114987... × 10^-10", -"mod(2.1053343141e10,2*pi) = mod(+(1+1015407956983808/2^52)*2.0^(34),2*pi) = 3.14159265358803985795440116897841971042021517833477967739316353946961929456928513638954697817331482676215697424765189761886478806761130057095656216451331963726299562891172796860029936414962898830731399848419...", -"mod(1.783366216531e12,2*pi) = mod(+(1+2801068395540480/2^52)*2.0^(40),2*pi) = 6.96948240875758165283364652450017592218369365167838571237684767728582201531913110512760529814875987841007291472111488973274399752796445730686810635597303227231604049063965142781067801484038929704503126... × 10^-13", -"mod(3.587785776203e12,2*pi) = mod(+(1+2844185642293248/2^52)*2.0^(41),2*pi) = 3.14159265358943375443615268530898643972511521351921641612349921661209466410474230079261080439434034782178672622333391220180901104555784937046215505597469325853419023536619117669842729443519112391028207634360...", -"mod(5.371151992734e12,2*pi) = mod(+(1+996460013189120/2^52)*2.0^(42),2*pi) = 3.14159265359013070267702844347426980437756523111143478548866705518333234887247088299414271750485310835160160221117491949328112253453112377021495150170538006916978753859342278074749125957797219171176611527331...", -"mod(8.958937768937e12,2*pi) = mod(+(1+83376510325248/2^52)*2.0^(43),2*pi) = 6.28318530717956445711318112878325624410268044463065120161216627179542701297721318378675352189919345617338832843450883169509013358008897314067710655768007332770397777395961395744591855401316331562204819161692...", -"mod(1.39755218526789e14,2*pi) = mod(+(1+4440734358344000/2^52)*2.0^(46),2*pi) = 3.14159265358980040549544387683802694000268991931802818042282336288024535494439868095440078572924291148798393333033819550681778794934825392861076762305204646122093106692947650926948023108695327813103005666278...", -"mod(4.28224593349304e14,2*pi) = mod(+(1+2347993866218368/2^52)*2.0^(48),2*pi) = 3.14159265358979271974893922617932552732207260508431245898085799120489745266557323213781657771845391870874778237239419162716811898993140599960797179432228824156563456394028940083212066878222733029361050389004...", -"mod(5.706674932067741e15,2*pi) = mod(+(1+1203075304697245/2^52)*2.0^(52),2*pi) = 4.23754646451256218416429262194162608653524752956234482551589924717953528741279504902951631892985510393600689510284748380679359369235443057957270202960326099424609213900534623202922619105230013018255129... × 10^-16", -"mod(6.134899525417045e15,2*pi) = mod(+(1+1631299898046549/2^52)*2.0^(52),2*pi) = 3.14159265358979314350358567743554394375133479924692111250561094743938000425549795009134531899795882166037967535790458522785762927467978667896734102976534619883583752426638882544133456931685053321622960912005..." +# Test Cases. Each row contains: x, x mod 2pi, x mod pi, x mod pi/2 (as from Wolfram Alpha) +# The values x are: +# -pi/2, pi/2, -pi, pi, 2pi, -2pi +# (or rather, the Float64 approx to those numbers. +# Thus, x mod pi will result in a small, but positive number) +# ΓΓ = 6411027962775774 / 2^47 +# from [2], section 1.2: +# the Float64 greater than 8, and less than 2**63 − 1 closest to a multiple of π/4 is +# Γ = 6411027962775774 / 2^48. We take ΓΓ = 2*Γ to get cancellation with pi/2 already +# 3.14159265359, -3.14159265359 +# pi/16*k +/- 0.00001 for k in [-20:20] # to cover all quadrants +# numerators of continuous fraction approximations to pi +# see http://oeis.org/A002485 +# (reason: for max cancellation, we want x = k*pi + eps for small eps, so x/k ≈ pi) + +testCases = [ + -1.5707963267948966 4.71238898038469 1.5707963267948968 6.123233995736766e-17; + 1.5707963267948966 1.5707963267948966 1.5707963267948966 1.5707963267948966; + -3.141592653589793 3.1415926535897936 1.2246467991473532e-16 1.2246467991473532e-16; + 3.141592653589793 3.141592653589793 3.141592653589793 1.5707963267948966; + 6.283185307179586 6.283185307179586 3.141592653589793 1.5707963267948963; + -6.283185307179586 2.4492935982947064e-16 2.4492935982947064e-16 2.4492935982947064e-16; + 45.553093477052 1.5707963267948966 1.5707963267948966 6.189806365883577e-19; + 3.14159265359 3.14159265359 2.0682310711021444e-13 2.0682310711021444e-13; + -3.14159265359 3.1415926535895866 3.1415926535895866 1.5707963267946898; + -3.9269808169872418 2.356204490192345 2.356204490192345 0.7854081633974481; + -3.73063127613788 2.5525540310417068 2.5525540310417068 0.98175770424681; + -3.5342817352885176 2.748903571891069 2.748903571891069 1.1781072450961723; + -3.337932194439156 2.945253112740431 2.945253112740431 1.374456785945534; + -3.1415826535897935 3.141602653589793 9.999999999743887e-6 9.999999999743887e-6; + -2.9452331127404316 3.337952194439155 0.19635954084936158 0.19635954084936158; + -2.7488835718910694 3.5343017352885173 0.39270908169872387 0.39270908169872387; + -2.5525340310417075 3.730651276137879 0.5890586225480857 0.5890586225480857; + -2.356184490192345 3.9270008169872415 0.785408163397448 0.785408163397448; + -2.1598349493429834 4.123350357836603 0.9817577042468099 0.9817577042468099; + -1.9634854084936209 4.319699898685966 1.1781072450961725 1.1781072450961725; + -1.7671358676442588 4.516049439535328 1.3744567859455346 1.3744567859455346; + -1.5707863267948967 4.71239898038469 1.5708063267948966 9.9999999999047e-6; + -1.3744367859455346 4.908748521234052 1.7671558676442587 0.19635954084936197; + -1.1780872450961726 5.105098062083414 1.9635054084936208 0.39270908169872404; + -0.9817377042468104 5.301447602932776 2.159854949342983 0.5890586225480863; + -0.7853881633974483 5.4977971437821385 2.356204490192345 0.7854081633974483; + -0.5890386225480863 5.6941466846315 2.552554031041707 0.9817577042468104; + -0.3926890816987242 5.890496225480862 2.748903571891069 1.1781072450961725; + -0.1963395408493621 6.0868457663302244 2.9452531127404313 1.3744567859455346; + 1.0e-5 1.0e-5 1.0e-5 1.0e-5; + 0.19635954084936205 0.19635954084936205 0.19635954084936205 0.19635954084936205; + 0.3927090816987241 0.3927090816987241 0.3927090816987241 0.3927090816987241; + 0.5890586225480862 0.5890586225480862 0.5890586225480862 0.5890586225480862; + 0.7854081633974482 0.7854081633974482 0.7854081633974482 0.7854081633974482; + 0.9817577042468103 0.9817577042468103 0.9817577042468103 0.9817577042468103; + 1.1781072450961723 1.1781072450961723 1.1781072450961723 1.1781072450961723; + 1.3744567859455343 1.3744567859455343 1.3744567859455343 1.3744567859455343; + 1.5708063267948964 1.5708063267948964 1.5708063267948964 9.999999999782235e-6; + 1.7671558676442585 1.7671558676442585 1.7671558676442585 0.19635954084936186; + 1.9635054084936205 1.9635054084936205 1.9635054084936205 0.3927090816987239; + 2.159854949342982 2.159854949342982 2.159854949342982 0.5890586225480855; + 2.3562044901923445 2.3562044901923445 2.3562044901923445 0.7854081633974478; + 2.5525540310417063 2.5525540310417063 2.5525540310417063 0.9817577042468096; + 2.7489035718910686 2.7489035718910686 2.7489035718910686 1.178107245096172; + 2.9452531127404304 2.9452531127404304 2.9452531127404304 1.3744567859455339; + 3.1416026535897927 3.1416026535897927 9.999999999498959e-6 9.999999999498959e-6; + 3.3379521944391546 3.3379521944391546 0.19635954084936136 0.19635954084936136; + 3.534301735288517 3.534301735288517 0.39270908169872365 0.39270908169872365; + 3.7306512761378787 3.7306512761378787 0.5890586225480855 0.5890586225480855; + 3.927000816987241 3.927000816987241 0.7854081633974478 0.7854081633974478; + -3.9270008169872415 2.356184490192345 2.356184490192345 0.7853881633974484; + -3.7306512761378796 2.552534031041707 2.552534031041707 0.9817377042468103; + -3.5343017352885173 2.7488835718910694 2.7488835718910694 1.1780872450961726; + -3.3379521944391555 2.945233112740431 2.945233112740431 1.3744367859455344; + -3.141602653589793 3.1415826535897935 3.1415826535897935 1.5707863267948967; + -2.9452531127404313 3.3379321944391553 0.1963395408493619 0.1963395408493619; + -2.748903571891069 3.5342817352885176 0.3926890816987242 0.3926890816987242; + -2.552554031041707 3.7306312761378795 0.589038622548086 0.589038622548086; + -2.356204490192345 3.9269808169872418 0.7853881633974483 0.7853881633974483; + -2.159854949342983 4.123330357836603 0.9817377042468102 0.9817377042468102; + -1.9635054084936208 4.3196798986859655 1.1780872450961726 1.1780872450961726; + -1.7671558676442587 4.516029439535328 1.3744367859455346 1.3744367859455346; + -1.5708063267948966 4.71237898038469 1.5707863267948967 1.5707863267948967; + -1.3744567859455346 4.908728521234052 1.7671358676442588 0.19633954084936206; + -1.1781072450961725 5.105078062083414 1.9634854084936209 0.39268908169872413; + -0.9817577042468104 5.301427602932776 2.159834949342983 0.5890386225480863; + -0.7854081633974483 5.497777143782138 2.3561844901923448 0.7853881633974483; + -0.5890586225480863 5.694126684631501 2.552534031041707 0.9817377042468104; + -0.39270908169872415 5.890476225480862 2.748883571891069 1.1780872450961726; + -0.19635954084936208 6.086825766330224 2.945233112740431 1.3744367859455346; + -1.0e-5 6.283175307179587 3.141582653589793 1.5707863267948967; + 0.19633954084936206 0.19633954084936206 0.19633954084936206 0.19633954084936206; + 0.39268908169872413 0.39268908169872413 0.39268908169872413 0.39268908169872413; + 0.5890386225480861 0.5890386225480861 0.5890386225480861 0.5890386225480861; + 0.7853881633974482 0.7853881633974482 0.7853881633974482 0.7853881633974482; + 0.9817377042468103 0.9817377042468103 0.9817377042468103 0.9817377042468103; + 1.1780872450961724 1.1780872450961724 1.1780872450961724 1.1780872450961724; + 1.3744367859455344 1.3744367859455344 1.3744367859455344 1.3744367859455344; + 1.5707863267948965 1.5707863267948965 1.5707863267948965 1.5707863267948965; + 1.7671358676442586 1.7671358676442586 1.7671358676442586 0.19633954084936195; + 1.9634854084936206 1.9634854084936206 1.9634854084936206 0.392689081698724; + 2.1598349493429825 2.1598349493429825 2.1598349493429825 0.5890386225480858; + 2.3561844901923448 2.3561844901923448 2.3561844901923448 0.7853881633974481; + 2.5525340310417066 2.5525340310417066 2.5525340310417066 0.98173770424681; + 2.748883571891069 2.748883571891069 2.748883571891069 1.1780872450961724; + 2.9452331127404308 2.9452331127404308 2.9452331127404308 1.3744367859455342; + 3.141582653589793 3.141582653589793 3.141582653589793 1.5707863267948965; + 3.337932194439155 3.337932194439155 0.19633954084936167 0.19633954084936167; + 3.534281735288517 3.534281735288517 0.39268908169872396 0.39268908169872396; + 3.730631276137879 3.730631276137879 0.5890386225480858 0.5890386225480858; + 3.9269808169872413 3.9269808169872413 0.7853881633974481 0.7853881633974481; + 22.0 3.1504440784612404 0.008851424871447331 0.008851424871447331; + 333.0 6.2743640266615035 3.13277137307171 1.5619750462768134; + 355.0 3.1416227979431572 3.014435336405372e-5 3.014435336405372e-5; + 103993.0 6.283166177843807 3.1415735242540137 1.570777197459117; + 104348.0 3.141603668607378 1.10150175844633e-5 1.10150175844633e-5; + 208341.0 3.141584539271598 3.141584539271598 1.5707882124767014; + 312689.0 2.9006993893361787e-6 2.9006993893361787e-6 2.9006993893361787e-6; + 833719.0 3.1415903406703767 3.1415903406703767 1.5707940138754801; + 1.146408e6 3.1415932413697663 5.877799728814151e-7 5.877799728814151e-7; + 4.272943e6 6.283184757600089 3.1415921040102956 1.5707957772153989; + 5.419351e6 3.1415926917902683 3.820047507089661e-8 3.820047507089661e-8; + 8.0143857e7 6.283185292406739 3.1415926388169466 1.5707963120220498; + 1.65707065e8 3.1415926622445745 8.654781434964792e-9 8.654781434964792e-9; + 2.45850922e8 3.141592647471728 3.141592647471728 1.5707963206768312; + 4.11557987e8 2.5367160519636766e-9 2.5367160519636766e-9 2.5367160519636766e-9; + 1.068966896e9 3.14159265254516 3.14159265254516 1.5707963257502633; + 2.549491779e9 4.474494938161497e-10 4.474494938161497e-10 4.474494938161497e-10; + 6.167950454e9 3.141592653440059 3.141592653440059 1.5707963266451623; + 1.4885392687e10 1.4798091093322177e-10 1.4798091093322177e-10 1.4798091093322177e-10; + 2.1053343141e10 3.14159265358804 3.14159265358804 1.5707963267931433; + 1.783366216531e12 6.969482408757582e-13 6.969482408757582e-13 6.969482408757582e-13; + 3.587785776203e12 3.141592653589434 3.141592653589434 1.570796326794537; + 5.371151992734e12 3.1415926535901306 3.374642143850602e-13 3.374642143850602e-13; + 8.958937768937e12 6.283185307179564 3.1415926535897714 1.5707963267948746; + 1.39755218526789e14 3.1415926535898 7.167032800493559e-15 7.167032800493559e-15; + 4.28224593349304e14 3.1415926535897927 3.1415926535897927 1.5707963267948961; + 5.706674932067741e15 4.237546464512562e-16 4.237546464512562e-16 4.237546464512562e-16; + 6.134899525417045e15 3.141592653589793 3.141592653589793 1.5707963267948966; ] - - - -## pi/2 -modpio2Solns = [ -"mod(-1.5707963267948966,pi/2) = mod(-(1+2570638124657944/2^52)*2^(0),pi/2) = 6.12323399573676588613032966137500529104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144054878329667... × 10^-17", -"mod(1.5707963267948966,pi/2) = mod(+(1+2570638124657944/2^52)*2^(0),pi/2) = 1.5707963267948965579989817342720925807952880859375", -"mod(-3.141592653589793,pi/2) = mod(-(1+2570638124657944/2^52)*2^(1),pi/2) = 1.22464679914735317722606593227500105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933... × 10^-16", -"mod(3.141592653589793,pi/2) = mod(+(1+2570638124657944/2^52)*2^(1),pi/2) = 1.57079632679489649676664177690443371949199147218744708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(6.283185307179586,pi/2) = mod(+(1+2570638124657944/2^52)*2^(2),pi/2) = 1.57079632679489637430196186216911599688539824468734126853758311153827539057068650205794776198682439802677787023007654002935923308567412665241196088780727832382457384594709221834166053306557656760442705335678...", -"mod(-6.283185307179586,pi/2) = mod(-(1+2570638124657944/2^52)*2^(2),pi/2) = 2.44929359829470635445213186455000211641949889184615632812572417997256069650684234135964296173026564613294187689219101164463450718816256962234900568205403877042211119289245897909860763928857621951331866... × 10^-16", -"mod(45.553093477052,pi/2) = mod(+(1+1907428335405278/2^52)*2.0^(5),pi/2) = 6.18980636588357700015067146560965595863303411536662108849969519893495032539302514258852745557406553617139253161516557639982288582137023796970880510821891443969385152967240153509461515782240852843965031... × 10^-19", -"mod(3.14159265359,pi/2) = mod(+(1+2570638124658410/2^52)*2.0^(1),pi/2) = 2.06823107110214443817242336338901406144179025055407692183593713791001371965174657882932017851913486717693352906155390449417768274640591871518882549715897298061478894440355377051045069618035571189024334... × 10^-13", -"mod(-3.14159265359,pi/2) = mod(-(1+2570638124658410/2^52)*2.0^(1),pi/2) = 1.57079632679468979612421147719593419976224579828140873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.9269808169872418,pi/2) = mod(-(1+4339175044666918/2^52)*2.0^(1),pi/2) = 0.78540816339744808411934112625764384217252411859390873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.73063127613788,pi/2) = mod(-(1+3897035185165141/2^52)*2.0^(1),pi/2) = 0.98175770424680993182460891801034733004560151117203373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.5342817352885176,pi/2) = mod(-(1+3454895325663363/2^52)*2.0^(1),pi/2) = 1.17810724509617222361908655982566698737134614007828373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.337932194439156,pi/2) = mod(-(1+3012755466161586/2^52)*2.0^(1),pi/2) = 1.37445678594553407132435435157837047524442353265640873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.1415826535897935,pi/2) = mod(-(1+2570615606659808/2^52)*2.0^(1),pi/2) = 9.9999999997438875103017539386904715834618751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288... × 10^-6", -"mod(-2.9452331127404316,pi/2) = mod(-(1+2128475747158031/2^52)*2.0^(1),pi/2) = 0.19635954084936159159277809350664217834466085445323082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.7488835718910694,pi/2) = mod(-(1+1686335887656253/2^52)*2.0^(1),pi/2) = 0.39270908169872388338725573532196183567040548335948082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.5525340310417075,pi/2) = mod(-(1+1244196028154476/2^52)*2.0^(1),pi/2) = 0.58905862254808573109252352707466532354348287593760582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.356184490192345,pi/2) = mod(-(1+802056168652698/2^52)*2.0^(1),pi/2) = 0.78540816339744802288700116888998498086922750484385582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.1598349493429834,pi/2) = mod(-(1+359916309150921/2^52)*2.0^(1),pi/2) = 0.98175770424680987059226896064268846874230489742198082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.9634854084936209,pi/2) = mod(-(1+4339152526668781/2^52)*2.0^(0),pi/2) = 1.17810724509617238443135152748931621079438314449229332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.7671358676442588,pi/2) = mod(-(1+3454872807665226/2^52)*2.0^(0),pi/2) = 1.37445678594553445418122424427332778339379415523448082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.5707863267948967,pi/2) = mod(-(1+2570593088661671/2^52)*2.0^(0),pi/2) = 9.9999999999046997752694175879138946204662891154104874722961539082031431044993140174126710585339910740432566411533235469223047752911158626797040642405587251420513509692605527798223114744774651909822144... × 10^-6", -"mod(-1.3744367859455346,pi/2) = mod(-(1+1686313369658116/2^52)*2.0^(0),pi/2) = 0.19635954084936197444964798620159948649403147703130291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-1.1780872450961726,pi/2) = mod(-(1+802033650654561/2^52)*2.0^(0),pi/2) = 0.39270908169872404419952070298561105909344248777349041048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.9817377042468104,pi/2) = mod(-(1+4339107490672507/2^52)*2.0^(-1),pi/2) = 0.58905862254808622497169588228527667405602030759770916048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.7853881633974483,pi/2) = mod(-(1+2570548052665397/2^52)*2.0^(-1),pi/2) = 0.78540816339744829472156859906928824665543131833989666048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.5890386225480863,pi/2) = mod(-(1+801988614658287/2^52)*2.0^(-1),pi/2) = 0.98175770424681036447144131585329981925484232908208416048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.3926890816987242,pi/2) = mod(-(1+2570457980672850/2^52)*2.0^(-2),pi/2) = 1.17810724509617243422131403263731139185425333982427166048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.1963395408493621,pi/2) = mod(-(1+2570277836687755/2^52)*2.0^(-3),pi/2) = 1.37445678594553453172676236505023647504445605283696697298747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(1.0e-5,pi/2) = mod(+(1+1399358476216561/2^52)*2.0^(-17),pi/2) = 0.000010000000000000000818030539140313095458623138256371021270751953125", -"mod(0.19635954084936205,pi/2) = mod(+(1+2570998412628133/2^52)*2.0^(-3),pi/2) = 0.1963595408493620519951861069785081781446933746337890625", -"mod(0.3927090816987241,pi/2) = mod(+(1+2570818268643038/2^52)*2.0^(-2),pi/2) = 0.39270908169872409398948320813360624015331268310546875", -"mod(0.5890586225480862,pi/2) = mod(+(1+802168758643381/2^52)*2.0^(-1),pi/2) = 0.58905862254808616373935592491761781275272369384765625", -"mod(0.7854081633974482,pi/2) = mod(+(1+2570728196650491/2^52)*2.0^(-1),pi/2) = 0.78540816339744823348922864170162938535213470458984375", -"mod(0.9817577042468103,pi/2) = mod(+(1+4339287634657601/2^52)*2.0^(-1),pi/2) = 0.98175770424681030323910135848564095795154571533203125", -"mod(1.1781072450961723,pi/2) = mod(+(1+802123722647107/2^52)*2.0^(0),pi/2) = 1.1781072450961722619666716127539984881877899169921875", -"mod(1.3744567859455343,pi/2) = mod(+(1+1686403441650662/2^52)*2.0^(0),pi/2) = 1.374456785945534331716544329538010060787200927734375", -"mod(1.5708063267948964,pi/2) = mod(+(1+2570683160654217/2^52)*2.0^(0),pi/2) = 9.9999999997822350953546822701912880272387890095895125277038460917968568955006859825873289414660089259567433588466764530776952247088841373202959357594412748579486490307394472201776885255225348090177856... × 10^-6", -"mod(1.7671558676442585,pi/2) = mod(+(1+3454962879657772/2^52)*2.0^(0),pi/2) = 0.19635954084936185198496807146628176388743824953119708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(1.9635054084936205,pi/2) = mod(+(1+4339242598661327/2^52)*2.0^(0),pi/2) = 0.39270908169872392173484078825029333648684926027338458951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.159854949342982,pi/2) = mod(+(1+359961345147192/2^52)*2.0^(1),pi/2) = 0.58905862254808554739550365497168873963359303468744708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.3562044901923445,pi/2) = mod(+(1+802101204648970/2^52)*2.0^(1),pi/2) = 0.78540816339744783918998129678700839695933766359369708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.5525540310417063,pi/2) = mod(+(1+1244241064150747/2^52)*2.0^(1),pi/2) = 0.98175770424680968689524908853971188483241505617182208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.7489035718910686,pi/2) = mod(+(1+1686380923652525/2^52)*2.0^(1),pi/2) = 1.17810724509617197868972673035503154215815968507807208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.9452531127404304,pi/2) = mod(+(1+2128520783154302/2^52)*2.0^(1),pi/2) = 1.37445678594553382639499452210773503003123707765619708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(3.1416026535897927,pi/2) = mod(+(1+2570660642656080/2^52)*2.0^(1),pi/2) = 9.9999999994989581504722833032452583970068748941790250554076921835937137910013719651746578829320178519134867176933529061553904494177682746405918715188825497158972980614788944403553770510450696180355712... × 10^-6", -"mod(3.3379521944391546,pi/2) = mod(+(1+3012800502157857/2^52)*2.0^(1),pi/2) = 0.19635954084936134666341826403600673313147439945301917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.534301735288517,pi/2) = mod(+(1+3454940361659635/2^52)*2.0^(1),pi/2) = 0.39270908169872363845789590585132639045721902835926917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.7306512761378787,pi/2) = mod(+(1+3897080221161412/2^52)*2.0^(1),pi/2) = 0.58905862254808548616316369760402987833029642093739417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.927000816987241,pi/2) = mod(+(1+4339220080663190/2^52)*2.0^(1),pi/2) = 0.78540816339744777795764133941934953565604104984364417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(-3.9270008169872415,pi/2) = mod(-(1+4339220080663191/2^52)*2.0^(1),pi/2) = 0.78538816339744839718447050215778573698987641351578373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.7306512761378796,pi/2) = mod(-(1+3897080221161414/2^52)*2.0^(1),pi/2) = 0.98173770424681024488973829391048922486295380609390873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.5343017352885173,pi/2) = mod(-(1+3454940361659636/2^52)*2.0^(1),pi/2) = 1.17808724509617253668421593572580888218869843500015873146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.3379521944391555,pi/2) = mod(-(1+3012800502157859/2^52)*2.0^(1),pi/2) = 1.37443678594553438438948372747851237006177582757828373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-3.141602653589793,pi/2) = mod(-(1+2570660642656081/2^52)*2.0^(1),pi/2) = 1.57078632679489667618396136929383202738752045648453373146241688846172460942931349794205223801317560197322212976992345997064076691432587334758803911219272167617542615405290778165833946693442343239557294664321...", -"mod(-2.9452531127404313,pi/2) = mod(-(1+2128520783154304/2^52)*2.0^(1),pi/2) = 0.19633954084936190465790746940678407316201314937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.748903571891069,pi/2) = mod(-(1+1686380923652526/2^52)*2.0^(1),pi/2) = 0.39268908169872419645238511122210373048775777828135582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.552554031041707,pi/2) = mod(-(1+1244241064150749/2^52)*2.0^(1),pi/2) = 0.58903862254808604415765290297480721836083517085948082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.356204490192345,pi/2) = mod(-(1+802101204648971/2^52)*2.0^(1),pi/2) = 0.78538816339744833595213054479012687568657979976573082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-2.159854949342983,pi/2) = mod(-(1+359961345147194/2^52)*2.0^(1),pi/2) = 0.98173770424681018365739833654283036355965719234385582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.9635054084936208,pi/2) = mod(-(1+4339242598661328/2^52)*2.0^(0),pi/2) = 1.17808724509617247545187597835815002088540182125010582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.7671558676442587,pi/2) = mod(-(1+3454962879657773/2^52)*2.0^(0),pi/2) = 1.37443678594553454520174869514216159348481283199229332097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.5708063267948966,pi/2) = mod(-(1+2570683160654218/2^52)*2.0^(0),pi/2) = 1.57078632679489661495162141192617316608422384273448082097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881...", -"mod(-1.3744567859455346,pi/2) = mod(-(1+1686403441650663/2^52)*2.0^(0),pi/2) = 0.19633954084936206547017243707043329658505015378911541048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-1.1781072450961725,pi/2) = mod(-(1+802123722647108/2^52)*2.0^(0),pi/2) = 0.39268908169872413522004515385444486918446116453130291048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.9817577042468104,pi/2) = mod(-(1+4339287634657602/2^52)*2.0^(-1),pi/2) = 0.58903862254808620496991787063845644178387217527349041048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.7854081633974483,pi/2) = mod(-(1+2570728196650492/2^52)*2.0^(-1),pi/2) = 0.78538816339744827471979058742246801438328318601567791048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.5890586225480863,pi/2) = mod(-(1+802168758643382/2^52)*2.0^(-1),pi/2) = 0.98173770424681034446966330420647958698269419675786541048747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.39270908169872415,pi/2) = mod(-(1+2570818268643039/2^52)*2.0^(-2),pi/2) = 1.17808724509617246973068725224831818076368861204106853548747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-0.19635954084936208,pi/2) = mod(-(1+2570998412628134/2^52)*2.0^(-3),pi/2) = 1.37443678594553453948055996903232975336309962278325603548747229615390820314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(-1.0e-5,pi/2) = mod(-(1+1399358476216561/2^52)*2.0^(-17),pi/2) = 1.57078632679489661923050366110061112900312607654929653946620154420078320314310449931401741267105853399107404325664115332354692230477529111586267970406424055872514205135096926055277982231147447746519098221440...", -"mod(0.19633954084936206,pi/2) = mod(+(1+2570277836687754/2^52)*2.0^(-3),pi/2) = 0.196339540849362059748983710960601456463336944580078125", -"mod(0.39268908169872413,pi/2) = mod(+(1+2570457980672849/2^52)*2.0^(-2),pi/2) = 0.392689081698724129498856427744613029062747955322265625", -"mod(0.5890386225480861,pi/2) = mod(+(1+801988614658286/2^52)*2.0^(-1),pi/2) = 0.5890386225480861437375779132707975804805755615234375", -"mod(0.7853881633974482,pi/2) = mod(+(1+2570548052665396/2^52)*2.0^(-1),pi/2) = 0.785388163397448213487450630054809153079986572265625", -"mod(0.9817377042468103,pi/2) = mod(+(1+4339107490672506/2^52)*2.0^(-1),pi/2) = 0.9817377042468102832373233468388207256793975830078125", -"mod(1.1780872450961724,pi/2) = mod(+(1+802033650654560/2^52)*2.0^(0),pi/2) = 1.17808724509617235298719606362283229827880859375", -"mod(1.3744367859455344,pi/2) = mod(+(1+1686313369658115/2^52)*2.0^(0),pi/2) = 1.3744367859455344227370687804068438708782196044921875", -"mod(1.5707863267948965,pi/2) = mod(+(1+2570593088661670/2^52)*2.0^(0),pi/2) = 1.570786326794896492486941497190855443477630615234375", -"mod(1.7671358676442586,pi/2) = mod(+(1+3454872807665225/2^52)*2.0^(0),pi/2) = 0.19633954084936194300549252233511557397845692628900958951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(1.9634854084936206,pi/2) = mod(+(1+4339152526668780/2^52)*2.0^(0),pi/2) = 0.39268908169872401275536523911912714657786793703119708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.1598349493429825,pi/2) = mod(+(1+359916309150919/2^52)*2.0^(1),pi/2) = 0.58903862254808586046063303087183063445094532960932208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.3561844901923448,pi/2) = mod(+(1+802056168652697/2^52)*2.0^(1),pi/2) = 0.78538816339744815225511067268715029177668995851557208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.5525340310417066,pi/2) = mod(+(1+1244196028154474/2^52)*2.0^(1),pi/2) = 0.98173770424680999996037846443985377964976735109369708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.748883571891069,pi/2) = mod(+(1+1686335887656252/2^52)*2.0^(1),pi/2) = 1.17808724509617229175485610625517343697551197999994708951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(2.9452331127404308,pi/2) = mod(+(1+2128475747158029/2^52)*2.0^(1),pi/2) = 1.37443678594553413946012389800787692484858937257807208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(3.141582653589793,pi/2) = mod(+(1+2570615606659807/2^52)*2.0^(1),pi/2) = 1.57078632679489643125460153982319658217433400148432208951252770384609179685689550068598258732894146600892595674335884667645307769522470888413732029593575944127485794864903073944722017768852552253480901778559...", -"mod(3.337932194439155,pi/2) = mod(+(1+3012755466161584/2^52)*2.0^(1),pi/2) = 0.19633954084936165972854763993614862794882669437489417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.534281735288517,pi/2) = mod(+(1+3454895325663362/2^52)*2.0^(1),pi/2) = 0.39268908169872395152302528175146828527457132328114417902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.730631276137879,pi/2) = mod(+(1+3897035185165139/2^52)*2.0^(1),pi/2) = 0.58903862254808579922829307350417177314764871585926917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(3.9269808169872413,pi/2) = mod(+(1+4339175044666917/2^52)*2.0^(1),pi/2) = 0.78538816339744809102277071531949143047339334476551917902505540769218359371379100137196517465788293201785191348671769335290615539044941776827464059187151888254971589729806147889444035537705104506961803557118...", -"mod(22.0,pi/2) = mod(+(1+1688849860263936/2^52)*2.0^(4),pi/2) = 0.00885142487144733076149631704347981061981420437425925317538785384528515599653700960375622260518052412496339440702385347034308773314592437792248414310063217784801128108643035226108248763935731548732624899832...", -"mod(333.0,pi/2) = mod(+(1+1354598325420032/2^52)*2.0^(8),pi/2) = 1.56197504627681334219112306401244571719862836592633588714334551152536913680495064474232592640664932788337687284871664873159939369241357455297458244244524210899502716494548602336345749227888525484470275276044...", -"mod(355.0,pi/2) = mod(+(1+1741626418397184/2^52)*2.0^(8),pi/2) = 0.00003014435336405372129768941617408571985787061304222983126106921674608965838315503206473634077131801726622399909934887839555912078420781503438688148163372811789639468094711507176015760676809286683801954435...", -"mod(103993.0,pi/2) = mod(+(1+2642744916836352/2^52)*2.0^(16),pi/2) = 1.57077719745911702881004837353527874739712658493466699787157772281522731705283191410522893791187418892511428058572652122310265696140225654301555183508229071942077441178204362431742351345516837196140445971348...", -"mod(104348.0,pi/2) = mod(+(1+2667140331077632/2^52)*2.0^(16),pi/2) = 0.00001101501758446330002437131170139101839975586015631721536649587806520356811056982327626158158697295130646132818471677795129377741117324218725901249968388881352875511202147883640384875046198736305149704344...", -"mod(208341.0,pi/2) = mod(+(1+2654942623956992/2^52)*2.0^(17),pi/2) = 1.57078821247670149211007274484698013841552634079482331508694421869329252062094248392850519949346116187642074191391123800105395073881342978520281084758197460823430316689406510315382736220563035932445595675693...", -"mod(312689.0,pi/2) = mod(+(1+868356487905280/2^52)*2.0^(18),pi/2) = 2.90069938933617877542451893008733534139696742672181483841841744952104594855443776404840398960083665315998545480145545832221144931191152739015601741793832268987065511732143745138864461786922231647158597... × 10^-6", -"mod(833719.0,pi/2) = mod(+(1+2657992050737152/2^52)*2.0^(19),pi/2) = 1.57079401387548016446762359388484031308620913472967675871662105552819156271283959280403329630144036354972706188482084091197059516171205360825759115961681048487968290820429974602873013949486609776908889992887...", -"mod(1.146408e6,pi/2) = mod(+(1+420185240502272/2^52)*2.0^(20),pi/2) = 5.87779972881415077326764018958322965832009550570043987177791732880615683647927779932034371430395306178613634489043881995068386074403922301611569987864477230727508447806913401705828009489526214389300436... × 10^-7", -"mod(4.272943e6,pi/2) = mod(+(1+84437983297536/2^52)*2.0^(22),pi/2) = 1.57079577721539880871285557417689718805510663075832846884858258890339020455989053658737309240455465473564559772572430804361658036687027682002449599432677407831137509072964316676893525697889456634773206783018...", -"mod(5.419351e6,pi/2) = mod(+(1+1315384200265728/2^52)*2.0^(22),pi/2) = 3.82004750708966112093011647042794877630803261284050974705412148820324696852011356117678675511398777330827176437639516531304810601080841179018325213840634637668871217131295571404954295784087554749162140... × 10^-8", -"mod(8.0143857e7,pi/2) = mod(+(1+874763572477952/2^52)*2.0^(26),pi/2) = 1.57079631202204980126541250439320304796793531388289426651994717648039855301446612940327165715470037069393386088377132073893972419360511833320214661998207345519986782714934715058273522391490866407030871665717...", -"mod(1.65707065e8,pi/2) = mod(+(1+1056606817091584/2^52)*2.0^(27),pi/2) = 8.65478143496479283480806791601818899147100884047004723119419558177519294537964410073515122454559736833697797859473725690814071454276305173366818717701291531848387749318946794370229795161899094380176246... × 10^-9", -"mod(2.45850922e8,pi/2) = mod(+(1+3745788417015808/2^52)*2.0^(27),pi/2) = 1.57079632067683123623020533920127096398612430535390310698999440767459413478965907478291575788985159523953122922074929933367698110174583287596519835365026063221278314563322464377220316761720661568929966045894...", -"mod(4.11557987e8,pi/2) = mod(+(1+2401197617053696/2^52)*2.0^(28),pi/2) = 2.53671605196367648236958743790572859713735903697256934271488151342174752084854244595394428579405455430108612460486731570511125630286557038325420725050055641276613287640889128900803008984309962204629913... × 10^-9", -"mod(1.068966896e9,pi/2) = mod(+(1+4463544628150272/2^52)*2.0^(29),pi/2) = 1.57079632575026334015755830394044583979758149962862118093513309310435716163315411648000064979774016682764033782292154854341161251196834548169633912015867513321389597116549039658998574563326679537549890455154...", -"mod(2.549491779e9,pi/2) = mod(+(1+843072155942912/2^52)*2.0^(31),pi/2) = 4.47449493816149706970976233303722197019495577867890936615779430401846755180508920207307551467187143433646915044596696119497365034532889215443076399478064252395175148483303135651614725663715466720569020... × 10^-10", -"mod(6.167950454e9,pi/2) = mod(+(1+1963965187883008/2^52)*2.0^(32),pi/2) = 1.57079632664516232778985771788239830640502589366761233667091496633591602243684762684101849021235526976201462469021537863260500475096307555076211755104482793217002447595584069355659201693649624670292983799267...", -"mod(1.4885392687e10,pi/2) = mod(+(1+3300633133711360/2^52)*2.0^(33),pi/2) = 1.47980910933221759456269961916604584979614430234776276979795068989333010234511075289901023009068306300795365662712861011872933904331764909404251146367829101604918014490927524901658264139193178277114987... × 10^-10", -"mod(2.1053343141e10,pi/2) = mod(+(1+1015407956983808/2^52)*2.0^(34),pi/2) = 1.57079632679314323872307947733866826832163047864722676690569124331571109142618063707552956550225629277108293099101074429531786576283600945509388246044907907853785357756075870804751954183815451084212301626979...", -"mod(1.783366216531e12,pi/2) = mod(+(1+2801068395540480/2^52)*2.0^(40),pi/2) = 6.96948240875758165283364652450017592218369365167838571237684767728582201531913110512760529814875987841007291472111488973274399752796445730686810635597303227231604049063965142781067801484038929704503126... × 10^-13", -"mod(3.587785776203e12,pi/2) = mod(+(1+2844185642293248/2^52)*2.0^(41),pi/2) = 1.57079632679453713520483099366923499762653051383166350563602692045818646096163780147859339172328181383071268296669275887826208874078255825459947535191045269980904818401522191614564747212371664644509109412920...", -"mod(5.371151992734e12,pi/2) = mod(+(1+996460013189120/2^52)*2.0^(42),pi/2) = 3.37464214385060194766920180395831736328964513722462875515942586261884366107892162736040369453515697892612846187277924980541538489592093576898951719503435891484259641931614955023236781384150844501479806... × 10^-13", -"mod(8.958937768937e12,pi/2) = mod(+(1+83376510325248/2^52)*2.0^(43),pi/2) = 1.57079632679487459941921605386400191780692634556799247014974938333370240354789968584470128388601785420016619866458537172444936666576309979308906744548735165152855161990670617578757908707873988322647524497370...", -"mod(1.39755218526789e14,pi/2) = mod(+(1+4440734358344000/2^52)*2.0^(46),pi/2) = 7.16703280049355852405580552051994292235944787877057242894865818968232636596038712584350583584681705588885972394333979767169688540821492356534377064696422753798816392058646400432320064809223397832709837... × 10^-15", -"mod(4.28224593349304e14,pi/2) = mod(+(1+2347993866218368/2^52)*2.0^(48),pi/2) = 1.57079632679489610051761753453957408522348790539675954849338569505098924952246873282379916504739538471767373911575303830362119668515611488374529209025804768284049251258932014027934084647075285282841952167563...", -"mod(5.706674932067741e15,pi/2) = mod(+(1+1203075304697245/2^52)*2.0^(52),pi/2) = 4.23754646451256218416429262194162608653524752956234482551589924717953528741279504902951631892985510393600689510284748380679359369235443057957270202960326099424609213900534623202922619105230013018255129... × 10^-16", -"mod(6.134899525417045e15,pi/2) = mod(+(1+1631299898046549/2^52)*2.0^(52),pi/2) = 1.57079632679489652427226398579579250165275009955936820201813865128547180111239345077732790632690028766930563210126343190431070696990449556310466132570110564011069547291541956488855474700537605575103862690565..." -] - - - function testModPi() - for divisorStr in ["2pi","pi","pi/2"] - numbersRegEx = r"[^(]*\(([^,]*),[^(]*\(([^,]*),[^=]*= ([0-9]*.[0-9]+)[^^]*\^?(-?[0-9]+)?" - xDivisor = eval(parse(divisorStr)) - tol = eps(Float64) * xDivisor - - normalizedDivisorStr = replace(divisorStr,"/","o") # 2pi, pi, pio2 - solnList = eval(parse("mod" * normalizedDivisorStr * "Solns")) # see below: mod2piSolns, modpiSolns, modpio2Solns - modFn = eval(parse("mod" * normalizedDivisorStr)) - - print("Testing mod"*normalizedDivisorStr, " with ", length(solnList), " instances... ") - errsNew, errsOld = Array(Float64,0), Array(Float64,0) - for testCase in solnList - decStr, exactStr, solnSignificand, solnExponent = match(numbersRegEx,testCase).captures - solnStr = solnExponent == nothing ? solnSignificand : string(solnSignificand, "e", solnExponent) - # print(lpad(decStr,20," "),": ") - xDec = eval(parse(convert(ASCIIString,decStr))) - xExact = eval(parse(convert(ASCIIString,exactStr))) - xSoln = eval(parse(convert(ASCIIString,solnStr))) - # 1. want: xDec ≈ xExact (dfference of the original x in different representations (decimal vs exact)) - # (might be off because for some x::Float64, if we have eval(parse(repr(x))) != x) + verbose = false + numTestCases = size(testCases,1) + println("Testing mod2pi, modpi, modpio2 with $numTestCases instances... ") + + modFns = [mod2pi,modpi,modpio2] + xDivisors = [2pi,pi,pi/2] + errsNew, errsOld = Array(Float64,0), Array(Float64,0) + for rowIdx in 1:numTestCases + xExact = testCases[rowIdx,1] + verbose && print(lpad(string(xExact),25," ")) + for colIdx in 1:3 + xSoln = testCases[rowIdx,colIdx+1] + xDivisor = xDivisors[colIdx] + modFn = modFns[colIdx] # 2. want: xNew := modFn(xExact) ≈ xSoln <--- this is the crucial bit, xNew close to xSoln # 3. know: xOld := mod(xExact,xDivisor) might be quite a bit off from xSoln - that's expected - xOld = mod(xExact,xDivisor) xNew = modFn(xExact) + xOld = mod(xExact,xDivisor) - reprDiff = abs(xDec - xExact) # should be zero newDiff = abs(xNew - xSoln) # should be zero, ideally (our new function) oldDiff = abs(xOld - xSoln) # should be zero in a perfect world, but often bigger due to cancellation oldDiff = min(oldDiff, abs(xDivisor - oldDiff)) # we are being generous here: - # if xOld happens to end up "on the wrong side of 0", ie + # if xOld happens to end up "on the wrong side of 0", eg # if xSoln = 3.14 (correct), but xOld reports 0.01, # we don't take the long way around the circle of 3.14 - 0.01, but the short way of 3.1415.. - (3.14 - 0.1) - # if reprDiff == zero(reprDiff) - # print("Repr ok ") - # else print("Repr ERR ") end - # if abs(newDiff) <= tol && abs(newDiff) <= abs(oldDiff) - # print("new ok ") - # else print("new ERR ") end push!(errsNew,abs(newDiff)) push!(errsOld,abs(oldDiff)) - # println("RepErr $(reprDiff) NewErr $(newDiff) OldErr $(oldDiff)") end - sort!(errsNew) - sort!(errsOld) - totalErrNew = sum(errsNew) - totalErrOld = sum(errsOld) - @test_approx_eq totalErrNew 0.0 - println("Total err = $totalErrNew (new), $totalErrOld (old).") - end -end - - -function testModPiPerformance() - N, runs = 10000, 10 - for divisorStr in ["2pi","pi","pi/2"] - xDivisor = eval(parse(divisorStr)) - normalizedDivisorStr = replace(divisorStr,"/","o") # 2pi, pi, pio2 - modFn = eval(parse("mod" * normalizedDivisorStr)) - - newTimes, oldTimes = Array(Float64,0), Array(Float64,0) - println("Speed: ") - for k = 1:runs - testCases = vcat(repmat(allTestCases(),N),linspace(-1e30,1e30,100*N) .* randn(100*N)) - oldTime = @elapsed for tc in testCases x = mod(tc,pi) end - newTime = @elapsed for tc in testCases x = modFn(tc) end - push!(oldTimes, oldTime) - push!(newTimes, newTime) - println("Items: $(length(testCases)) NewTime: $newTime, OldTime: $oldTime, Ratio: $(newTime/oldTime)") + if verbose + if sum(errsNew[end-2:]) == 0 + print(" ok ") + else print(" ERR ") end + print("diffs new $(errsNew[end-2]) $(errsNew[end-1]) $(errsNew[end]) ") + print("diffs old $(errsOld[end-2]) $(errsOld[end-1]) $(errsOld[end])\n") end - println("Averages:") - println("Items: $(runs) NewTime: $(mean(newTimes)), OldTime: $(mean(oldTimes)), Ratio: $(sum(newTimes)/sum(oldTimes))") end + sort!(errsNew) + sort!(errsOld) + totalErrNew = sum(errsNew) + totalErrOld = sum(errsOld) + @test_approx_eq totalErrNew 0.0 + println("Total err = $totalErrNew (new), $totalErrOld (old).") end -# NOTE: this function used only for timing currently, all testcases are hardcoded -function allTestCases() # for modpi - deltaPi = 0.00001 - pips = [π/16*k + deltaPi for k in [-20:20]] # multiples of pi/16 plus a bit - pims = [π/16*k - deltaPi for k in [-20:20]] # multiples of pi/16 minus a bit - - # numerators of continuous fraction approximations to pi - # see http://oeis.org/A002485 - # (reason: for max cancellation, we want x = k*pi + eps for small eps, so x/k ≈ pi) - contFractionNumerators = [22, 333, 355, 103993, 104348, 208341, 312689, 833719, 1146408, - 4272943, 5419351, 80143857, 165707065, 245850922, 411557987, 1068966896, 2549491779, 6167950454, - 14885392687, 21053343141, 1783366216531, 3587785776203, 5371151992734, 8958937768937, 139755218526789, - 428224593349304, 5706674932067741, 6134899525417045 ] - # note: these numerators below are too big to represent as a Float64 exactly - # 30246273033735921, 66627445592888887, 430010946591069243, 2646693125139304345 - # (all natural numbers <= 9007199254740992 can be represented as a Float64 exactly) - closeToPi = 3.14159265359 - - ΓΓ = 6411027962775774 / 2^47 - # from [2], section 1.2: - # the Float64 greater than 8, and less than 2**63 − 1 closest to a multiple of π/4 is - # Γ = 6411027962775774 / 2^48 - # Gamma mod pi/4 should be ε ≈ 3.9405531196482 × 10^−19 - # Wolfram Alpha: mod( 6411027962775774 * 2^(-48) , pi/4) - # = 3.094903182941788500075335732804827979316517057683310544... × 10^-19 - # we take twice Γ, as we want to be close to pi/2, not pi/4 - # ΓΓ = 2*Γ - - return vcat([-pi/2, pi/2, -pi, pi, 2pi, -2pi, ΓΓ,closeToPi,-closeToPi],pips,pims,contFractionNumerators) -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(355) 3.1416227979431572 @test_approx_eq mod2pi(int32(355)) 3.1416227979431572 @test_approx_eq mod2pi(355.0) 3.1416227979431572 @@ -511,11 +211,7 @@ testModPi() @test mod2pi(2^60) == mod2pi(2.0^60) @test_throws mod2pi(2^60-1) - -@test_approx_eq mod(355,pi) 3.014435336405372e-5 -@test_approx_eq mod(int32(355),pi) 3.014435336405372e-5 -@test_approx_eq mod(355.0,pi) 3.014435336405372e-5 -@test_approx_eq mod(355.0f0,pi) 3.0144354f-5 +# pi - also test that mod(x,pi) == modpi(x) @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 @@ -523,6 +219,12 @@ 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(355) 3.014435336405372e-5 @test_approx_eq modpio2(int32(355)) 3.014435336405372e-5 @test_approx_eq modpio2(355.0) 3.014435336405372e-5 From 2dbb37dc54ef42f5b949d357ffafb3ad84a68658 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Sun, 17 Nov 2013 18:13:41 -0500 Subject: [PATCH 10/11] =?UTF-8?q?do=20NOT=20add=20a=20methods=20for=20mod(?= =?UTF-8?q?x,y::MathConst{:=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) + From 3f7edd3218403f202047402494c752c1ce6c5ec2 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Mon, 18 Nov 2013 11:33:28 -0500 Subject: [PATCH 11/11] added modpi etc. documentation. Updated the example for round() using non-ten basis --- doc/stdlib/base.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 38ffce7d0e6fa..c83a326362d82 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -1972,6 +1972,18 @@ Mathematical Operators Modulus after division, returning in the range [0,m) +.. function:: modpi(x) + + Modulus after division by pi, returning in the range [0,pi). More accurate than mod(x,pi). + +.. function:: mod2pi(x) + + Modulus after division by 2pi, returning in the range [0,2pi). More accurate than mod(x,2pi). + +.. function:: modpio2(x) + + Modulus after division by pi/2, returning in the range [0,pi/2). More accurate than mod(x,pi/2). + .. function:: rem(x, m) Remainder after division @@ -2468,7 +2480,7 @@ Mathematical Functions .. function:: round(x, [digits, [base]]) - ``round(x)`` returns the nearest integral value of the same type as ``x`` to ``x``. ``round(x, digits)`` rounds to the specified number of digits after the decimal place, or before if negative, e.g., ``round(pi,2)`` is ``3.14``. ``round(x, digits, base)`` rounds using a different base, defaulting to 10, e.g., ``round(pi, 3, 2)`` is ``3.125``. + ``round(x)`` returns the nearest integral value of the same type as ``x`` to ``x``. ``round(x, digits)`` rounds to the specified number of digits after the decimal place, or before if negative, e.g., ``round(pi,2)`` is ``3.14``. ``round(x, digits, base)`` rounds using a different base, defaulting to 10, e.g., ``round(pi, 1, 8)`` is ``3.125``. .. function:: ceil(x, [digits, [base]])