From cfa682c8cb005aed4adeda210d060fb97ec7a9a8 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 28 Aug 2013 18:47:25 -0400 Subject: [PATCH 01/89] add the ability to specify the address of a native function as a finalizer the advantage of this is that we know no julia code runs, so it is safe to free the underlying object immediately, rather than waiting for another GC cycle to be sure no references to the object were added. this is specifically designed for BigInt and BigFloat, which get faster and use less memory with this change (helps #4169) --- base/base.jl | 2 +- base/gmp.jl | 7 ++++++- base/mpfr.jl | 2 +- src/gc.c | 11 ++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/base/base.jl b/base/base.jl index a542d1b05700b..a9996459e20f8 100644 --- a/base/base.jl +++ b/base/base.jl @@ -84,7 +84,7 @@ isequal(w::WeakRef, v::WeakRef) = isequal(w.value, v.value) isequal(w::WeakRef, v) = isequal(w.value, v) isequal(w, v::WeakRef) = isequal(w, v.value) -function finalizer(o::ANY, f::Function) +function finalizer(o::ANY, f::Union(Function,Ptr)) if isimmutable(o) error("objects of type ", typeof(o), " cannot be finalized") end diff --git a/base/gmp.jl b/base/gmp.jl index 10927eb001e8b..7d47d006eb142 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -15,7 +15,7 @@ type BigInt <: Integer function BigInt() b = new(zero(Cint), zero(Cint), C_NULL) ccall((:__gmpz_init,:libgmp), Void, (Ptr{BigInt},), &b) - finalizer(b, BigInt_clear) + finalizer(b, _gmp_clear_func) return b end end @@ -24,7 +24,12 @@ function BigInt_clear(mpz::BigInt) ccall((:__gmpz_clear, :libgmp), Void, (Ptr{BigInt},), &mpz) end +_gmp_clear_func = C_NULL +_mpfr_clear_func = C_NULL + function gmp_init() + global _gmp_clear_func = cglobal((:__gmpz_clear, :libgmp)) + global _mpfr_clear_func = cglobal((:mpfr_clear, :libmpfr)) ccall((:__gmp_set_memory_functions, :libgmp), Void, (Ptr{Void},Ptr{Void},Ptr{Void}), cglobal(:jl_gc_counted_malloc), diff --git a/base/mpfr.jl b/base/mpfr.jl index 1ec78a5c7a7ea..9457d4b099f14 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -44,7 +44,7 @@ type BigFloat <: FloatingPoint N = get_bigfloat_precision() z = new(zero(Clong), zero(Cint), zero(Clong), C_NULL) ccall((:mpfr_init2,:libmpfr), Void, (Ptr{BigFloat}, Clong), &z, N) - finalizer(z, MPFR_clear) + finalizer(z, Base.GMP._mpfr_clear_func) return z end # Not recommended for general use diff --git a/src/gc.c b/src/gc.c index 5654b9b82584d..f9f084ac32883 100644 --- a/src/gc.c +++ b/src/gc.c @@ -314,7 +314,8 @@ static void run_finalizers(void) void jl_gc_run_all_finalizers() { for(size_t i=0; i < finalizer_table.size; i+=2) { - if (finalizer_table.table[i+1] != HT_NOTFOUND) { + jl_value_t *f = finalizer_table.table[i+1]; + if (f != HT_NOTFOUND && !jl_is_cpointer(f)) { schedule_finalization(finalizer_table.table[i]); } } @@ -856,6 +857,14 @@ static void gc_mark(void) if (finalizer_table.table[i+1] != HT_NOTFOUND) { jl_value_t *v = finalizer_table.table[i]; if (!gc_marked(v)) { + jl_value_t *fin = finalizer_table.table[i+1]; + if (gc_typeof(fin) == (jl_value_t*)jl_voidpointer_type) { + void *p = ((void**)fin)[1]; + if (p) + ((void (*)(void*))p)(&((void**)v)[1]); + finalizer_table.table[i+1] = HT_NOTFOUND; + continue; + } gc_push_root(v, 0); schedule_finalization(v); } From 4d83f892e11008a165d55ca05833e971c4937f38 Mon Sep 17 00:00:00 2001 From: Fabian R Lischka Date: Wed, 13 Nov 2013 01:04:33 -0500 Subject: [PATCH 02/89] 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 03/89] 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 04/89] 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 05/89] 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 06/89] 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 07/89] 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 08/89] 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 09/89] 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 10/89] 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 11/89] =?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 12/89] 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]]) From 1dee2464697abb8fe762f921fab96fe08e3ac652 Mon Sep 17 00:00:00 2001 From: Lei Wang Date: Tue, 19 Nov 2013 21:37:09 +0800 Subject: [PATCH 13/89] conv and conv2 --- base/dsp.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base/dsp.jl b/base/dsp.jl index d2318dbe02ce4..d78d1aa8fcc06 100644 --- a/base/dsp.jl +++ b/base/dsp.jl @@ -94,7 +94,7 @@ function conv{T<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{T} end return y[1:n] end -conv{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}) = conv(float(u), float(v)) +conv{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}) = int(conv(float(u), float(v))) conv{T<:Integer, S<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{S}) = conv(float(u), v) conv{T<:Integer, S<:Base.LinAlg.BlasFloat}(u::StridedVector{S}, v::StridedVector{T}) = conv(u, float(v)) @@ -125,6 +125,8 @@ function conv2{T}(A::StridedMatrix{T}, B::StridedMatrix{T}) end return C end +conv2{T<:Integer}(A::StridedMatrix{T}, B::StridedMatrix{T}) = int(conv2(float(A), float(B))) +conv2{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}, A::StridedMatrix{T}) = int(conv2(float(u), float(v), float(A))) function xcorr(u, v) su = size(u,1); sv = size(v,1) From 3634f181f09ee5c1867911f067902d1be675b94f Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Tue, 19 Nov 2013 21:16:31 -0500 Subject: [PATCH 14/89] mod2pi: remove modpi and modpio2, adding a single function to Base. This is kind of a painful edit since there's a lot of great work in here, but it's just too much to add three functions to Base. mod2pi seems like the most sensible of these functions. If we find that there is great need for the other versions, we can always resurrect them in the future by the wonders of git history. --- base/exports.jl | 4 +- base/math.jl | 104 ++--------------- test/math-modpi.jl | 286 ++++++++++++++++++++------------------------- 3 files changed, 137 insertions(+), 257 deletions(-) diff --git a/base/exports.jl b/base/exports.jl index bb3d933994c83..d8a83cd7f4a1e 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -381,10 +381,8 @@ export maxintfloat, mod, mod1, - mod2pi, modf, - modpi, - modpio2, + mod2pi, nan, nextfloat, nextpow, diff --git a/base/math.jl b/base/math.jl index a3b84fff58923..6a5476624f730 100644 --- a/base/math.jl +++ b/base/math.jl @@ -11,8 +11,7 @@ export sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, cbrt, sqrt, erf, erfc, erfcx, erfi, dawson, ceil, floor, trunc, round, significand, lgamma, hypot, gamma, lfact, max, min, ldexp, frexp, - clamp, modf, ^, - mod2pi, modpi, modpio2, + clamp, modf, ^, mod2pi, airy, airyai, airyprime, airyaiprime, airybi, airybiprime, besselj0, besselj1, besselj, bessely0, bessely1, bessely, hankelh1, hankelh2, besseli, besselk, besselh, @@ -1338,20 +1337,9 @@ end erfcinv(x::Integer) = erfcinv(float(x)) @vectorize_1arg Real erfcinv +## mod2pi-related calculations ## -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) +function add22condh(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) @@ -1371,14 +1359,13 @@ function ieee754_rem_pio2(x::Float64) # (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 + # https://github.com/JuliaLang/openlibm/blob/master/src/e_rem_pio2.c y = [0.0,0.0] - n = ccall((:__ieee754_rem_pio2, libm), Cint, (Float64,Ptr{Float64}),x,y) + n = ccall((:__ieee754_rem_pio2, libm), Cint, (Float64,Ptr{Float64}), x, y) return (n,y) end - # 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) @@ -1392,7 +1379,6 @@ const pi3o2_l = 1.8369701987210297e-16 # convert(Float64, pi * BigFloat(3/2) - 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) # with r = mod2pi(x) # a) 0 <= r < 2π (note: boundary open or closed - a bit fuzzy, due to rem_pio2 implementation) @@ -1404,7 +1390,7 @@ function mod2pi(x::Float64) # or modtau(x) 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) + return add22condh(x,0.0,pi4o2_h,pi4o2_l) end end @@ -1412,95 +1398,29 @@ function mod2pi(x::Float64) # or modtau(x) if iseven(n) if n & 2 == 2 # add pi - return add22Cond_h(y[1],y[2],pi2o2_h,pi2o2_l) + return add22condh(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) + return add22condh(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) + return add22condh(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) + return add22condh(y[1],y[2],pi1o2_h,pi1o2_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 - -mod2pi(x::Float32)= float32(mod2pi(float64(x))) -mod2pi(x::Int32) = mod2pi(float64(x)) +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::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(modpio2(float64(x))) -modpio2(x::Int32) = modpio2(float64(x)) -function modpio2(x::Int64) - fx = float64(x) - fx == x || error("Integer argument to modpio2 is too large: $x") - modpio2(fx) -end - end # module diff --git a/test/math-modpi.jl b/test/math-modpi.jl index 51cfefc690592..79dfa5c1c4302 100644 --- a/test/math-modpi.jl +++ b/test/math-modpi.jl @@ -1,5 +1,3 @@ - - # 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 @@ -15,7 +13,7 @@ # 6.189806365883577000150671465609655958633034115366621088... × 10^-19 -# Test Cases. Each row contains: x, x mod 2pi, x mod pi, x mod pi/2 (as from Wolfram Alpha) +# Test Cases. Each row contains: x and x mod 2pi (as from Wolfram Alpha) # The values x are: # -pi/2, pi/2, -pi, pi, 2pi, -2pi # (or rather, the Float64 approx to those numbers. @@ -31,139 +29,135 @@ # (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; + -1.5707963267948966 4.71238898038469 + 1.5707963267948966 1.5707963267948966 + -3.141592653589793 3.1415926535897936 + 3.141592653589793 3.141592653589793 + 6.283185307179586 6.283185307179586 + -6.283185307179586 2.4492935982947064e-16 + 45.553093477052 1.5707963267948966 + 3.14159265359 3.14159265359 + -3.14159265359 3.1415926535895866 + -3.9269808169872418 2.356204490192345 + -3.73063127613788 2.5525540310417068 + -3.5342817352885176 2.748903571891069 + -3.337932194439156 2.945253112740431 + -3.1415826535897935 3.141602653589793 + -2.9452331127404316 3.337952194439155 + -2.7488835718910694 3.5343017352885173 + -2.5525340310417075 3.730651276137879 + -2.356184490192345 3.9270008169872415 + -2.1598349493429834 4.123350357836603 + -1.9634854084936209 4.319699898685966 + -1.7671358676442588 4.516049439535328 + -1.5707863267948967 4.71239898038469 + -1.3744367859455346 4.908748521234052 + -1.1780872450961726 5.105098062083414 + -0.9817377042468104 5.301447602932776 + -0.7853881633974483 5.4977971437821385 + -0.5890386225480863 5.6941466846315 + -0.3926890816987242 5.890496225480862 + -0.1963395408493621 6.0868457663302244 + 1.0e-5 1.0e-5 + 0.19635954084936205 0.19635954084936205 + 0.3927090816987241 0.3927090816987241 + 0.5890586225480862 0.5890586225480862 + 0.7854081633974482 0.7854081633974482 + 0.9817577042468103 0.9817577042468103 + 1.1781072450961723 1.1781072450961723 + 1.3744567859455343 1.3744567859455343 + 1.5708063267948964 1.5708063267948964 + 1.7671558676442585 1.7671558676442585 + 1.9635054084936205 1.9635054084936205 + 2.159854949342982 2.159854949342982 + 2.3562044901923445 2.3562044901923445 + 2.5525540310417063 2.5525540310417063 + 2.7489035718910686 2.7489035718910686 + 2.9452531127404304 2.9452531127404304 + 3.1416026535897927 3.1416026535897927 + 3.3379521944391546 3.3379521944391546 + 3.534301735288517 3.534301735288517 + 3.7306512761378787 3.7306512761378787 + 3.927000816987241 3.927000816987241 + -3.9270008169872415 2.356184490192345 + -3.7306512761378796 2.552534031041707 + -3.5343017352885173 2.7488835718910694 + -3.3379521944391555 2.945233112740431 + -3.141602653589793 3.1415826535897935 + -2.9452531127404313 3.3379321944391553 + -2.748903571891069 3.5342817352885176 + -2.552554031041707 3.7306312761378795 + -2.356204490192345 3.9269808169872418 + -2.159854949342983 4.123330357836603 + -1.9635054084936208 4.3196798986859655 + -1.7671558676442587 4.516029439535328 + -1.5708063267948966 4.71237898038469 + -1.3744567859455346 4.908728521234052 + -1.1781072450961725 5.105078062083414 + -0.9817577042468104 5.301427602932776 + -0.7854081633974483 5.497777143782138 + -0.5890586225480863 5.694126684631501 + -0.39270908169872415 5.890476225480862 + -0.19635954084936208 6.086825766330224 + -1.0e-5 6.283175307179587 + 0.19633954084936206 0.19633954084936206 + 0.39268908169872413 0.39268908169872413 + 0.5890386225480861 0.5890386225480861 + 0.7853881633974482 0.7853881633974482 + 0.9817377042468103 0.9817377042468103 + 1.1780872450961724 1.1780872450961724 + 1.3744367859455344 1.3744367859455344 + 1.5707863267948965 1.5707863267948965 + 1.7671358676442586 1.7671358676442586 + 1.9634854084936206 1.9634854084936206 + 2.1598349493429825 2.1598349493429825 + 2.3561844901923448 2.3561844901923448 + 2.5525340310417066 2.5525340310417066 + 2.748883571891069 2.748883571891069 + 2.9452331127404308 2.9452331127404308 + 3.141582653589793 3.141582653589793 + 3.337932194439155 3.337932194439155 + 3.534281735288517 3.534281735288517 + 3.730631276137879 3.730631276137879 + 3.9269808169872413 3.9269808169872413 + 22.0 3.1504440784612404 + 333.0 6.2743640266615035 + 355.0 3.1416227979431572 + 103993.0 6.283166177843807 + 104348.0 3.141603668607378 + 208341.0 3.141584539271598 + 312689.0 2.9006993893361787e-6 + 833719.0 3.1415903406703767 + 1.146408e6 3.1415932413697663 + 4.272943e6 6.283184757600089 + 5.419351e6 3.1415926917902683 + 8.0143857e7 6.283185292406739 + 1.65707065e8 3.1415926622445745 + 2.45850922e8 3.141592647471728 + 4.11557987e8 2.5367160519636766e-9 + 1.068966896e9 3.14159265254516 + 2.549491779e9 4.474494938161497e-10 + 6.167950454e9 3.141592653440059 + 1.4885392687e10 1.4798091093322177e-10 + 2.1053343141e10 3.14159265358804 + 1.783366216531e12 6.969482408757582e-13 + 3.587785776203e12 3.141592653589434 + 5.371151992734e12 3.1415926535901306 + 8.958937768937e12 6.283185307179564 + 1.39755218526789e14 3.1415926535898 + 4.28224593349304e14 3.1415926535897927 + 5.706674932067741e15 4.237546464512562e-16 + 6.134899525417045e15 3.141592653589793 ] function testModPi() - verbose = false numTestCases = size(testCases,1) - println("Testing mod2pi, modpi, modpio2 with $numTestCases instances... ") - - modFns = [mod2pi,modpi,modpio2] - xDivisors = [2pi,pi,pi/2] + modFns = [mod2pi] + xDivisors = [2pi] 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 + for colIdx in 1:1 xSoln = testCases[rowIdx,colIdx+1] xDivisor = xDivisors[colIdx] modFn = modFns[colIdx] @@ -181,25 +175,15 @@ function testModPi() push!(errsNew,abs(newDiff)) push!(errsOld,abs(oldDiff)) end - 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 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 - - - testModPi() + # 2pi @test_approx_eq mod2pi(10) mod(10,2pi) @test_approx_eq mod2pi(-10) mod(-10,2pi) @@ -209,25 +193,3 @@ testModPi() @test_approx_eq mod2pi(355.0f0) 3.1416228f0 @test mod2pi(2^60) == mod2pi(2.0^60) @test_throws mod2pi(2^60-1) - -# pi -@test_approx_eq modpi(10) mod(10,pi) -@test_approx_eq modpi(-10) mod(-10,pi) -@test_approx_eq modpi(355) 3.014435336405372e-5 -@test_approx_eq modpi(int32(355)) 3.014435336405372e-5 -@test_approx_eq modpi(355.0) 3.014435336405372e-5 -@test_approx_eq modpi(355.0f0) 3.0144354f-5 -@test modpi(2^60) == modpi(2.0^60) -@test_throws modpi(2^60-1) - - -# 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 84d975a67cafd459c355d2b03083b9957b4cee4a Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Tue, 19 Nov 2013 21:22:39 -0500 Subject: [PATCH 15/89] rename: test/math-modpi.jl => test/mod2pi.jl, add to test/Makefile --- test/Makefile | 2 +- test/{math-modpi.jl => mod2pi.jl} | 0 test/runtests.jl | 3 +-- 3 files changed, 2 insertions(+), 3 deletions(-) rename test/{math-modpi.jl => mod2pi.jl} (100%) diff --git a/test/Makefile b/test/Makefile index bad86d6c6d872..2c503fce875b5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -6,7 +6,7 @@ TESTS = all core keywordargs numbers strings unicode collections hashing \ math functional bigint sorting statistics spawn parallel arpack file \ git pkg resolve suitesparse complex version pollfd mpfr broadcast \ socket floatapprox priorityqueue readdlm regex float16 combinatorics \ - sysinfo rounding ranges + sysinfo rounding ranges mod2pi default: all diff --git a/test/math-modpi.jl b/test/mod2pi.jl similarity index 100% rename from test/math-modpi.jl rename to test/mod2pi.jl diff --git a/test/runtests.jl b/test/runtests.jl index 8ea8272cbe652..68397af2f1790 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,8 +6,7 @@ testnames = ["core", "keywordargs", "numbers", "strings", "unicode", "arpack", "file", "suitesparse", "version", "resolve", "pollfd", "mpfr", "broadcast", "complex", "socket", "floatapprox", "readdlm", "regex", "float16", - "combinatorics", "sysinfo", "rounding", "ranges", - "math-modpi"] + "combinatorics", "sysinfo", "rounding", "ranges", "mod2pi"] tests = ARGS==["all"] ? testnames : ARGS From ba0602f90862feb3d23b7ff58eab09593da1fc52 Mon Sep 17 00:00:00 2001 From: Jutho Date: Thu, 21 Nov 2013 23:26:53 +0100 Subject: [PATCH 16/89] added permutedims! Separated the permutedims method into a permutedims! method which stores the permutation a given array into a specified destination, and the wrapper permutedims which reproduces the original functionality by creating the required destination storage and then calling permutedims! on it. --- base/bitarray.jl | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index b5e8486ba4504..1d15ce0396dc7 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -2124,13 +2124,15 @@ ctranspose(B::BitArray) = transpose(B) ## Permute array dims ## let permutedims_cache = nothing, stridenames::Array{Any,1} = {} -global permutedims -function permutedims(B::Union(BitArray,StridedArray), perm) +global permutedims! +function permutedims!{T<:Union(BitArray,StridedArray)}(P::T,B::T, perm) dimsB = size(B) ndimsB = length(dimsB) - ndimsB == length(perm) || error("invalid dimensions") - dimsP = ntuple(ndimsB, i->dimsB[perm[i]])::typeof(dimsB) - P = similar(B, dimsP) + (ndimsB == length(perm) && isperm(perm)) || error("no valid permutation of dimensions") + dimsP = size(P) + ndimsP = length(dimsP) + (dimsP==dimsB[perm]) || error("destination tensor of incorrect size") + ranges = ntuple(ndimsB, i->(1:dimsP[i])) while length(stridenames) < ndimsB push!(stridenames, gensym()) @@ -2202,6 +2204,16 @@ function permutedims(B::Union(BitArray,StridedArray), perm) end end # let +function permutedims(B::Union(BitArray,StridedArray), perm) + dimsB = size(B) + ndimsB = length(dimsB) + (ndimsB == length(perm) && isperm(perm)) || error("no valid permutation of dimensions") + dimsP = ntuple(ndimsB, i->dimsB[perm[i]])::typeof(dimsB) + P = similar(B, dimsP) + permutedims!(P,B,perm) +end + + ## Concatenation ## function hcat(B::BitVector...) From 25a775cedaa06d01ef04562e92ba18b1485e85bc Mon Sep 17 00:00:00 2001 From: Jutho Date: Fri, 22 Nov 2013 00:38:58 +0100 Subject: [PATCH 17/89] Further changes to permutedims and tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this commit, all tests pass. I changed the permutedims tests to have permutations specified by vectors instead of tuples (which is also how it is stated in the manual). I also had to make two seperate versions of permutedims!: when B is a BitArray, P has to be a BitArray, whereas for B a StridedArray, P should be an Array. I don’t think it is possible to obtain this behavior in a single parametric definition. --- base/bitarray.jl | 79 +++++++++++++++++++++++++++++++++++++++++++++--- test/arrayops.jl | 4 +-- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 1d15ce0396dc7..03d62def5dba8 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -2125,7 +2125,7 @@ ctranspose(B::BitArray) = transpose(B) let permutedims_cache = nothing, stridenames::Array{Any,1} = {} global permutedims! -function permutedims!{T<:Union(BitArray,StridedArray)}(P::T,B::T, perm) +function permutedims!(P::BitArray,B::BitArray, perm) dimsB = size(B) ndimsB = length(dimsB) (ndimsB == length(perm) && isperm(perm)) || error("no valid permutation of dimensions") @@ -2139,12 +2139,81 @@ function permutedims!{T<:Union(BitArray,StridedArray)}(P::T,B::T, perm) end #calculates all the strides - if isa(B,BitArray) - strides = [ prod(dimsB[1:(perm[dim]-1)])::Int for dim = 1:length(perm) ] - else - strides = [ stride(B, perm[dim]) for dim = 1:length(perm) ] + strides = [ prod(dimsB[1:(perm[dim]-1)])::Int for dim = 1:length(perm) ] + + #Creates offset, because indexing starts at 1 + offset = 0 + for i in strides + offset+=i + end + offset = 1-offset + + if isa(B,SubArray) + offset += (B.first_index-1) + B = B.parent end + function permute_one_dim(ivars) + len = length(ivars) + counts = { symbol(string("count",i)) for i=1:len} + toReturn = cell(len+1,2) + for i = 1:length(toReturn) + toReturn[i] = nothing + end + + tmp = counts[end] + toReturn[len+1] = quote + ind = 1 + $tmp = $(stridenames[len]) + end + + #inner most loop + toReturn[1] = quote + P[ind] = B[+($(counts...))+offset] + ind+=1 + $(counts[1]) += $(stridenames[1]) + end + for i = 1:len-1 + tmp = counts[i] + val = i + toReturn[(i+1)] = quote + $tmp = $(stridenames[val]) + end + tmp2 = counts[i+1] + val = i+1 + toReturn[(i+1)+(len+1)] = quote + $tmp2 += $(stridenames[val]) + end + end + toReturn + end + + if is(permutedims_cache,nothing) + permutedims_cache = Dict() + end + + gen_cartesian_map(permutedims_cache, permute_one_dim, ranges, + tuple(:B, :P, :perm, :offset, stridenames[1:ndimsB]...), + B, P, perm, offset, strides...) + + return P +end +function permutedims!(P::Array,B::StridedArray, perm) + dimsB = size(B) + ndimsB = length(dimsB) + (ndimsB == length(perm) && isperm(perm)) || error("no valid permutation of dimensions") + dimsP = size(P) + ndimsP = length(dimsP) + (dimsP==dimsB[perm]) || error("destination tensor of incorrect size") + + ranges = ntuple(ndimsB, i->(1:dimsP[i])) + while length(stridenames) < ndimsB + push!(stridenames, gensym()) + end + + #calculates all the strides + strides = [ stride(B, perm[dim]) for dim = 1:length(perm) ] + #Creates offset, because indexing starts at 1 offset = 0 for i in strides diff --git a/test/arrayops.jl b/test/arrayops.jl index 90494a1c67955..9fae182e9c27f 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -308,7 +308,7 @@ for i = 1:3 end #permutes correctly -@test isequal(z,permutedims(y,(3,1,2))) +@test isequal(z,permutedims(y,[3,1,2])) # of a subarray a = rand(5,5) @@ -364,7 +364,7 @@ end for i = 1 : 3 a = rand(200, 300) - @test isequal(a', permutedims(a, (2, 1))) + @test isequal(a', permutedims(a, [2, 1])) end ## cumsum, cummin, cummax From 65dc7b9df6af505265e5d9acd2f35ac03500b539 Mon Sep 17 00:00:00 2001 From: Jutho Date: Fri, 22 Nov 2013 00:55:00 +0100 Subject: [PATCH 18/89] FixedSetPartitions Functionality for iterating over the partitions of a set into a fixed number of subsets. partitions(array,m) relates to partitions(array) like partitions(n,m) relates to partitions(n). --- base/combinatorics.jl | 70 ++++++++++++++++++++++++++++++++++++++++++- doc/stdlib/base.rst | 10 +++++++ test/combinatorics.jl | 2 ++ 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/base/combinatorics.jl b/base/combinatorics.jl index 134e8e5497674..5f010ab4076d2 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -308,7 +308,6 @@ function npartitions(n::Int) end end - # Algorithm H from TAoCP 7.2.1.4 # Partition n into m parts # in colex order (lexicographic by reflected sequence) @@ -436,6 +435,75 @@ function nsetpartitions(n::Int) end end +immutable FixedSetPartitions{T<:AbstractVector} + s::T + m::Int +end + +length(p::FixedSetPartitions) = nfixedsetpartitions(length(p.s),p.m) + +partitions(s::AbstractVector,m::Int) = (@assert 2 <= m <= length(s); FixedSetPartitions(s,m)) + +start(p::FixedSetPartitions) = (n = length(p.s);m=p.m; (vcat(ones(Int, n-m),1:m), vcat(1,n-m+2:n), n)) +# state consists of vector a of length n describing to which partition every element of s belongs and +# a vector b of length m describing the first index b[i] that belongs to partition i + +done(p::FixedSetPartitions, s) = !isempty(s) && s[1][1] > 1 +next(p::FixedSetPartitions, s) = nextfixedsetpartition(p.s,p.m, s...) + +function nextfixedsetpartition(s::AbstractVector,m, a, b, n) + function makeparts(s, a) + part = [ similar(s,0) for k = 1:m ] + for i = 1:n + push!(part[a[i]], s[i]) + end + return part + end + + part = makeparts(s,a) + + if a[end] != m + a[end] += 1 + else + local j, k + for j = n-1:-1:1 + if a[j]1 + a[j]+=1 + for p=j+1:n + if b[a[p]]!=p + a[p]=1 + end + end + else + for k=m:-1:2 + if b[k-1]= x diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 3682983bfae4e..bfd817a9b1cf9 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -3759,6 +3759,16 @@ Combinatorics The number of partitions to generete can be efficiently computed using ``length(partitions(array))``. +.. function:: partitions(array,m) + + Generate all set partitions of the elements of an array into exactly, + m subsets, represented as arrays of arrays. Because the number of + partitions can be very large, this function returns an iterator object. + Use ``collect(partitions(array))`` to get an array of all partitions. + The number of partitions into m subsets is equal to the Stirling number + of the second kind and can be efficiently computed using + ``length(partitions(array))``. + Statistics ---------- diff --git a/test/combinatorics.jl b/test/combinatorics.jl index 36458a06d4246..75688d1b14481 100644 --- a/test/combinatorics.jl +++ b/test/combinatorics.jl @@ -16,7 +16,9 @@ a = randcycle(10) @test collect(partitions(4)) == {[4], [3,1], [2,2], [2,1,1], [1,1,1,1]} @test collect(partitions(8,3)) == {[6,1,1], [5,2,1], [4,3,1], [4,2,2], [3,3,2]} @test collect(partitions([1,2,3])) == {{[1,2,3]}, {[1,2],[3]}, {[1,3],[2]}, {[1],[2,3]}, {[1],[2],[3]}} +@test collect(partitions([1,2,3,4],3)) == {{[1,2],[3],[4]}, {[1,3],[2],[4]}, {[1],[2,3],[4]}, {[1,4],[2],[3]}, {[1],[2,4],[3]},{[1],[2],[3,4]}} @test length(collect(partitions(30))) == length(partitions(30)) @test length(collect(partitions(90,4))) == length(partitions(90,4)) @test length(collect(partitions('a':'h'))) == length(partitions('a':'h')) +@test length(collect(partitions('a':'h',5))) == length(partitions('a':'h',5)) From ad4c70f73282c649d9b9b34e614542a57f9c8263 Mon Sep 17 00:00:00 2001 From: Jutho Date: Sat, 23 Nov 2013 22:34:22 +0100 Subject: [PATCH 19/89] fixed typo in description in manual --- doc/stdlib/base.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index bfd817a9b1cf9..39c31ec653754 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -3764,10 +3764,10 @@ Combinatorics Generate all set partitions of the elements of an array into exactly, m subsets, represented as arrays of arrays. Because the number of partitions can be very large, this function returns an iterator object. - Use ``collect(partitions(array))`` to get an array of all partitions. + Use ``collect(partitions(array,m))`` to get an array of all partitions. The number of partitions into m subsets is equal to the Stirling number of the second kind and can be efficiently computed using - ``length(partitions(array))``. + ``length(partitions(array,m))``. Statistics ---------- From 9a1f8e3d6056cb6b29a34dbfb5ba280a361f983c Mon Sep 17 00:00:00 2001 From: Jutho Date: Sun, 24 Nov 2013 10:14:40 +0100 Subject: [PATCH 20/89] Replaced tabs with spaces --- base/combinatorics.jl | 54 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/base/combinatorics.jl b/base/combinatorics.jl index 5f010ab4076d2..7af4cd5fe7421 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -437,7 +437,7 @@ end immutable FixedSetPartitions{T<:AbstractVector} s::T - m::Int + m::Int end length(p::FixedSetPartitions) = nfixedsetpartitions(length(p.s),p.m) @@ -457,7 +457,7 @@ function nextfixedsetpartition(s::AbstractVector,m, a, b, n) for i = 1:n push!(part[a[i]], s[i]) end - return part + return part end part = makeparts(s,a) @@ -471,37 +471,37 @@ function nextfixedsetpartition(s::AbstractVector,m, a, b, n) break end end - if j>1 - a[j]+=1 - for p=j+1:n - if b[a[p]]!=p - a[p]=1 - end - end - else - for k=m:-1:2 - if b[k-1]1 + a[j]+=1 + for p=j+1:n + if b[a[p]]!=p + a[p]=1 + end + end + else + for k=m:-1:2 + if b[k-1] Date: Sun, 1 Dec 2013 16:08:41 +0100 Subject: [PATCH 21/89] Removed type annotation of argument in isperm As requested --- base/combinatorics.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/combinatorics.jl b/base/combinatorics.jl index 134e8e5497674..4f81f64fb5c4a 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -114,7 +114,7 @@ function invperm(a::AbstractVector) b end -function isperm(A::AbstractVector) +function isperm(A) n = length(A) used = falses(n) for a in A From e9be4448fd269bf5915918a2cd272fda03109217 Mon Sep 17 00:00:00 2001 From: tknopp Date: Tue, 3 Dec 2013 17:22:24 +0100 Subject: [PATCH 22/89] Some work to make libjulia compilable on windows using the Intel compiler --- src/array.c | 2 +- src/ccall.cpp | 2 +- src/codegen.cpp | 7 ++++--- src/flisp/builtins.c | 6 +++--- src/init.c | 2 +- src/jl_uv.c | 8 ++++---- src/jltypes.c | 6 +++--- src/newobj_internal.h | 4 ++-- src/support/dtypes.h | 4 ++-- src/task.c | 2 +- 10 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/array.c b/src/array.c index 3717f97e2712b..99aaa9222cd29 100644 --- a/src/array.c +++ b/src/array.c @@ -24,7 +24,7 @@ int jl_array_store_unboxed(jl_value_t *el_type) // at this size use malloc #define MALLOC_THRESH 1048576 -#ifdef _P64 +#if defined(_P64) && defined(UINT128MAX) typedef __uint128_t wideint_t; #else typedef uint64_t wideint_t; diff --git a/src/ccall.cpp b/src/ccall.cpp index f7047171606fb..4245537f8c5d7 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -747,7 +747,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx) } // emit arguments - Value *argvals[(nargs-3)/2 + sret]; + std::vector argvals((nargs-3)/2 + sret); Value *result; if (sret) { assert(jl_is_structtype(rt)); diff --git a/src/codegen.cpp b/src/codegen.cpp index 28e31aed303a7..45f5f2c745897 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8,6 +8,7 @@ * including (or rather its content). */ #if defined(_OS_WINDOWS_) +#define NOMINMAX #include #if defined(_COMPILER_INTEL_) #include @@ -903,7 +904,7 @@ static Value *emit_lambda_closure(jl_value_t *expr, jl_codectx_t *ctx) int argStart = ctx->argDepth; size_t clen = jl_array_dim0(capt); - Value *captured[1+clen]; + std::vector captured(1+clen); captured[0] = ConstantInt::get(T_size, clen); for(i=0; i < clen; i++) { Value *val; @@ -1691,7 +1692,7 @@ static Value *emit_call(jl_value_t **args, size_t arglen, jl_codectx_t *ctx, Value *result; if (f!=NULL && specialized && f->linfo!=NULL && f->linfo->cFunctionObject!=NULL) { // emit specialized call site - Value *argvals[nargs]; + std::vector argvals(nargs); Function *cf = (Function*)f->linfo->cFunctionObject; FunctionType *cft = cf->getFunctionType(); for(size_t i=0; i < nargs; i++) { @@ -2409,7 +2410,7 @@ static Function *gen_jlcall_wrapper(jl_lambda_info_t *lam, Function *f) builder.SetCurrentDebugLocation(noDbg); size_t nargs = jl_tuple_len(lam->specTypes); - Value *args[nargs]; + std::vector args(nargs); for(size_t i=0; i < nargs; i++) { Value *argPtr = builder.CreateGEP(argArray, ConstantInt::get(T_size, i)); diff --git a/src/flisp/builtins.c b/src/flisp/builtins.c index 99a160d874257..1c34b5ce5d54a 100644 --- a/src/flisp/builtins.c +++ b/src/flisp/builtins.c @@ -308,19 +308,19 @@ static value_t fl_time_now(value_t *args, u_int32_t nargs) static value_t fl_path_cwd(value_t *args, uint32_t nargs) { - int err; + uv_err_t err; if (nargs > 1) argcount("path.cwd", nargs, 1); if (nargs == 0) { char buf[1024]; err = uv_cwd(buf, sizeof(buf)); - if (err != 0) + if (err.code != 0) lerrorf(IOError, "path.cwd: could not get cwd: %s", uv_strerror(err)); return string_from_cstr(buf); } char *ptr = tostring(args[0], "path.cwd"); err = uv_chdir(ptr); - if (err != 0) + if (err.code != 0) lerrorf(IOError, "path.cwd: could not cd to %s: %s", ptr, uv_strerror(err)); return FL_T; } diff --git a/src/init.c b/src/init.c index a19c378def024..a543d0adafd54 100644 --- a/src/init.c +++ b/src/init.c @@ -52,7 +52,7 @@ void __cdecl fpreset (void); #include #include extern int needsSymRefreshModuleList; -extern WINBOOL WINAPI (*hSymRefreshModuleList)(HANDLE); +extern BOOL (*hSymRefreshModuleList)(HANDLE); #endif #if defined(__linux__) //#define _GNU_SOURCE diff --git a/src/jl_uv.c b/src/jl_uv.c index 995ebb9e9ed22..4877f1af390b0 100644 --- a/src/jl_uv.c +++ b/src/jl_uv.c @@ -491,7 +491,7 @@ DLLEXPORT int jl_write_copy(uv_stream_t *stream, const char *str, size_t n, uv_w memcpy(data,str,n); uv_buf_t buf[] = {{.base = data,.len=n}}; uvw->data = NULL; - int err = uv_write(uvw,stream,buf,1,writecb); + int err = uv_write(uvw,stream,buf,1,(uv_write_cb)writecb); JL_SIGATOMIC_END(); return err; } @@ -532,7 +532,7 @@ DLLEXPORT int jl_write_no_copy(uv_stream_t *stream, char *data, size_t n, uv_wri { uv_buf_t buf[] = {{.base = data,.len=n}}; JL_SIGATOMIC_BEGIN(); - int err = uv_write(uvw,stream,buf,1,writecb); + int err = uv_write(uvw,stream,buf,1,(uv_write_cb)writecb); uvw->data = NULL; JL_SIGATOMIC_END(); return err; @@ -645,7 +645,7 @@ DLLEXPORT void jl_exit(int exitcode) DLLEXPORT int jl_cwd(char *buffer, size_t size) { - return uv_cwd(buffer,size); + return uv_cwd(buffer,size).code; } DLLEXPORT int jl_getpid() @@ -684,7 +684,7 @@ DLLEXPORT int jl_uv_sizeof_interface_address() DLLEXPORT int jl_uv_interface_addresses(uv_interface_address_t **ifAddrStruct,int *count) { - return uv_interface_addresses(ifAddrStruct,count); + return uv_interface_addresses(ifAddrStruct,count).code; } DLLEXPORT int jl_uv_interface_address_is_internal(uv_interface_address_t *addr) diff --git a/src/jltypes.c b/src/jltypes.c index 9a2411a892b27..c6b301ef22742 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -69,7 +69,7 @@ int jl_is_type(jl_value_t *v) return jl_is_nontuple_type(v); } -static inline int is_unspec(jl_datatype_t *dt) +STATIC_INLINE int is_unspec(jl_datatype_t *dt) { return (jl_datatype_t*)dt->name->primary == dt; } @@ -280,7 +280,7 @@ typedef struct { jl_tuple_t *tvars; } cenv_t; -static inline int is_bnd(jl_tvar_t *tv, cenv_t *env) +STATIC_INLINE int is_bnd(jl_tvar_t *tv, cenv_t *env) { if (jl_is_typevar(env->tvars)) return (jl_tvar_t*)env->tvars == tv; @@ -291,7 +291,7 @@ static inline int is_bnd(jl_tvar_t *tv, cenv_t *env) return 0; } -static inline int is_btv(jl_value_t *v) +STATIC_INLINE int is_btv(jl_value_t *v) { return jl_is_typevar(v) && ((jl_tvar_t*)v)->bound; } diff --git a/src/newobj_internal.h b/src/newobj_internal.h index 72d9ce4415ede..8fe94542226bd 100644 --- a/src/newobj_internal.h +++ b/src/newobj_internal.h @@ -1,14 +1,14 @@ #ifndef NEWOBJ_INTERNAL_H #define NEWOBJ_INTERNAL_H -static inline jl_value_t *newobj(jl_value_t *type, size_t nfields) +STATIC_INLINE jl_value_t *newobj(jl_value_t *type, size_t nfields) { jl_value_t *jv = (jl_value_t*)allocobj((1+nfields) * sizeof(void*)); jv->type = type; return jv; } -static inline jl_value_t *newstruct(jl_datatype_t *type) +STATIC_INLINE jl_value_t *newstruct(jl_datatype_t *type) { jl_value_t *jv = (jl_value_t*)allocobj(sizeof(void*) + type->size); jv->type = (jl_value_t*)type; diff --git a/src/support/dtypes.h b/src/support/dtypes.h index 7a78b38a01f7b..9001932fe1d5c 100644 --- a/src/support/dtypes.h +++ b/src/support/dtypes.h @@ -1,6 +1,8 @@ #ifndef DTYPES_H #define DTYPES_H +#include "platform.h" + #if !defined(_OS_WINDOWS_) #include #endif @@ -8,8 +10,6 @@ #include // double include of stddef.h fixes #3421 #include -#include "platform.h" - #if defined(_OS_WINDOWS_) #include diff --git a/src/task.c b/src/task.c index c6b6f6ae0406c..7d8da5efab243 100644 --- a/src/task.c +++ b/src/task.c @@ -530,7 +530,7 @@ static int frame_info_from_ip(const char **func_name, int *line_num, const char #if defined(_OS_WINDOWS_) int needsSymRefreshModuleList; -WINBOOL WINAPI (*hSymRefreshModuleList)(HANDLE); +BOOL (*hSymRefreshModuleList)(HANDLE); DLLEXPORT size_t rec_backtrace(ptrint_t *data, size_t maxsize) { CONTEXT Context; From b17f5488fc4388ad184d054ad0cf30d9a9e568fd Mon Sep 17 00:00:00 2001 From: Tobias Knopp Date: Tue, 3 Dec 2013 19:32:59 +0100 Subject: [PATCH 23/89] Revert the wrong uv_errno_t changes --- src/flisp/builtins.c | 6 +++--- src/jl_uv.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/flisp/builtins.c b/src/flisp/builtins.c index 1c34b5ce5d54a..99a160d874257 100644 --- a/src/flisp/builtins.c +++ b/src/flisp/builtins.c @@ -308,19 +308,19 @@ static value_t fl_time_now(value_t *args, u_int32_t nargs) static value_t fl_path_cwd(value_t *args, uint32_t nargs) { - uv_err_t err; + int err; if (nargs > 1) argcount("path.cwd", nargs, 1); if (nargs == 0) { char buf[1024]; err = uv_cwd(buf, sizeof(buf)); - if (err.code != 0) + if (err != 0) lerrorf(IOError, "path.cwd: could not get cwd: %s", uv_strerror(err)); return string_from_cstr(buf); } char *ptr = tostring(args[0], "path.cwd"); err = uv_chdir(ptr); - if (err.code != 0) + if (err != 0) lerrorf(IOError, "path.cwd: could not cd to %s: %s", ptr, uv_strerror(err)); return FL_T; } diff --git a/src/jl_uv.c b/src/jl_uv.c index 4877f1af390b0..6d6e069c707d8 100644 --- a/src/jl_uv.c +++ b/src/jl_uv.c @@ -645,7 +645,7 @@ DLLEXPORT void jl_exit(int exitcode) DLLEXPORT int jl_cwd(char *buffer, size_t size) { - return uv_cwd(buffer,size).code; + return uv_cwd(buffer,size); } DLLEXPORT int jl_getpid() @@ -684,7 +684,7 @@ DLLEXPORT int jl_uv_sizeof_interface_address() DLLEXPORT int jl_uv_interface_addresses(uv_interface_address_t **ifAddrStruct,int *count) { - return uv_interface_addresses(ifAddrStruct,count).code; + return uv_interface_addresses(ifAddrStruct,count); } DLLEXPORT int jl_uv_interface_address_is_internal(uv_interface_address_t *addr) From cf4094d39f147e42cca9da8239b986b3f7f4e86d Mon Sep 17 00:00:00 2001 From: Tobias Knopp Date: Tue, 3 Dec 2013 21:08:57 +0100 Subject: [PATCH 24/89] Use alloca where VLAs where originally used --- src/ccall.cpp | 2 +- src/codegen.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ccall.cpp b/src/ccall.cpp index 4245537f8c5d7..15ec8326702ae 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -747,7 +747,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx) } // emit arguments - std::vector argvals((nargs-3)/2 + sret); + Value **argvals = (Value**) alloca(((nargs-3)/2 + sret)*sizeof(Value*)); Value *result; if (sret) { assert(jl_is_structtype(rt)); diff --git a/src/codegen.cpp b/src/codegen.cpp index 45f5f2c745897..5761062c44823 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -904,7 +904,7 @@ static Value *emit_lambda_closure(jl_value_t *expr, jl_codectx_t *ctx) int argStart = ctx->argDepth; size_t clen = jl_array_dim0(capt); - std::vector captured(1+clen); + Value **captured = (Value**) alloca((1+clen)*sizeof(Value*)); captured[0] = ConstantInt::get(T_size, clen); for(i=0; i < clen; i++) { Value *val; @@ -1692,7 +1692,7 @@ static Value *emit_call(jl_value_t **args, size_t arglen, jl_codectx_t *ctx, Value *result; if (f!=NULL && specialized && f->linfo!=NULL && f->linfo->cFunctionObject!=NULL) { // emit specialized call site - std::vector argvals(nargs); + Value **argvals = (Value**) alloca(nargs*sizeof(Value*)); Function *cf = (Function*)f->linfo->cFunctionObject; FunctionType *cft = cf->getFunctionType(); for(size_t i=0; i < nargs; i++) { @@ -2410,7 +2410,7 @@ static Function *gen_jlcall_wrapper(jl_lambda_info_t *lam, Function *f) builder.SetCurrentDebugLocation(noDbg); size_t nargs = jl_tuple_len(lam->specTypes); - std::vector args(nargs); + Value **args = (Value**) alloca(nargs*sizeof(Value*)); for(size_t i=0; i < nargs; i++) { Value *argPtr = builder.CreateGEP(argArray, ConstantInt::get(T_size, i)); From cac2f18af7f520de2dca85c60e3c567aa2d4db3b Mon Sep 17 00:00:00 2001 From: tknopp Date: Wed, 4 Dec 2013 17:38:03 +0100 Subject: [PATCH 25/89] Fix DLLEXPORT macro on windows so that the default is import --- src/Makefile | 2 +- src/Makefile.debug | 2 +- src/flisp/Makefile | 2 +- src/support/Makefile | 2 +- src/support/dtypes.h | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Makefile b/src/Makefile index de01e5e3fd35c..98258723ae9bc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,7 +14,7 @@ FLAGS = \ -Wall -Wno-strict-aliasing -fno-omit-frame-pointer \ -Iflisp -Isupport -fvisibility=hidden -fno-common \ -I$(call exec,$(LLVM_CONFIG) --includedir) \ - -I$(LIBUV_INC) -I$(JULIAHOME)/usr/include + -I$(LIBUV_INC) -I$(JULIAHOME)/usr/include -DLIBRARY_EXPORTS LLVMLINK = $(call exec,$(LLVM_CONFIG) --libs) ifeq ($(USE_LLVM_SHLIB),1) diff --git a/src/Makefile.debug b/src/Makefile.debug index a5d0f6a46422b..2ec79e0cdb3a3 100644 --- a/src/Makefile.debug +++ b/src/Makefile.debug @@ -8,7 +8,7 @@ FLAGS = \ -Wall -Wno-strict-aliasing -fno-omit-frame-pointer \ -Iflisp -Isupport -fvisibility=hidden -fno-common \ -I$(call exec,$(LLVM_CONFIG) --includedir) \ - -I$(EXTROOT)/include + -I$(EXTROOT)/include -DLIBRARY_EXPORTS OBJS = $(SRCS:%=%.o) DOBJS = $(SRCS:%=%.do) diff --git a/src/flisp/Makefile b/src/flisp/Makefile index 9e9ecd5ebe3fb..01e609ef8eec6 100644 --- a/src/flisp/Makefile +++ b/src/flisp/Makefile @@ -18,7 +18,7 @@ LLT = $(LLTDIR)/libsupport.a $(LIBUV) FLAGS = -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) \ -DUSE_COMPUTED_GOTO $(HFILEDIRS:%=-I%) -I$(LIBUV_INC) $(LIBDIRS:%=-L%) \ - -fvisibility=hidden + -fvisibility=hidden -DLIBRARY_EXPORTS LIBFILES = $(LLT) LIBS = $(LIBFILES) ifneq ($(OS),WINNT) diff --git a/src/support/Makefile b/src/support/Makefile index 1a394ad556539..9eba3bdaadfbe 100644 --- a/src/support/Makefile +++ b/src/support/Makefile @@ -28,7 +28,7 @@ XOBJS = $(DOBJS) endif FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS) $(HFILEDIRS:%=-I%) -I$(LIBUV_INC) \ - -fvisibility=hidden + -fvisibility=hidden -DLIBRARY_EXPORTS DEBUGFLAGS += $(FLAGS) SHIPFLAGS += $(FLAGS) diff --git a/src/support/dtypes.h b/src/support/dtypes.h index 9001932fe1d5c..df08a737b6c20 100644 --- a/src/support/dtypes.h +++ b/src/support/dtypes.h @@ -55,10 +55,10 @@ #ifdef _OS_WINDOWS_ #define STDCALL __stdcall -# ifdef IMPORT_EXPORTS -# define DLLEXPORT __declspec(dllimport) -# else +# ifdef LIBRARY_EXPORTS # define DLLEXPORT __declspec(dllexport) +# else +# define DLLEXPORT __declspec(dllimport) # endif #else #define STDCALL From 5b3b303d300adc05eff4587b76cf3075b453cdc2 Mon Sep 17 00:00:00 2001 From: Tobias Knopp Date: Thu, 5 Dec 2013 07:18:54 +0100 Subject: [PATCH 26/89] moved inttype.h include below platform.h include --- src/support/dtypes.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/support/dtypes.h b/src/support/dtypes.h index df08a737b6c20..e16e0b91180df 100644 --- a/src/support/dtypes.h +++ b/src/support/dtypes.h @@ -1,14 +1,15 @@ #ifndef DTYPES_H #define DTYPES_H +#include +#include // double include of stddef.h fixes #3421 +#include + #include "platform.h" #if !defined(_OS_WINDOWS_) #include #endif -#include -#include // double include of stddef.h fixes #3421 -#include #if defined(_OS_WINDOWS_) From f64c3a8197baba001dfad44984fa8703ef822800 Mon Sep 17 00:00:00 2001 From: Tobias Knopp Date: Sun, 8 Dec 2013 10:06:42 +0100 Subject: [PATCH 27/89] add WINAPI again --- src/init.c | 2 +- src/task.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.c b/src/init.c index a543d0adafd54..7f18ff374cff4 100644 --- a/src/init.c +++ b/src/init.c @@ -52,7 +52,7 @@ void __cdecl fpreset (void); #include #include extern int needsSymRefreshModuleList; -extern BOOL (*hSymRefreshModuleList)(HANDLE); +extern BOOL (WINAPI *hSymRefreshModuleList)(HANDLE); #endif #if defined(__linux__) //#define _GNU_SOURCE diff --git a/src/task.c b/src/task.c index 7d8da5efab243..4d5ea5c59275f 100644 --- a/src/task.c +++ b/src/task.c @@ -530,7 +530,7 @@ static int frame_info_from_ip(const char **func_name, int *line_num, const char #if defined(_OS_WINDOWS_) int needsSymRefreshModuleList; -BOOL (*hSymRefreshModuleList)(HANDLE); +BOOL (WINAPI *hSymRefreshModuleList)(HANDLE); DLLEXPORT size_t rec_backtrace(ptrint_t *data, size_t maxsize) { CONTEXT Context; From e77e7eb22fdcadb56a3428b61f2a85380fb369d7 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Sun, 1 Dec 2013 21:48:03 +0000 Subject: [PATCH 28/89] add BitsFloat abstract type, leverage dispatch for rounding modes --- NEWS.md | 6 +++- base/deprecated.jl | 8 +++++ base/exports.jl | 3 -- base/mpfr.jl | 21 +++--------- base/rounding.jl | 12 +++---- .../integers-and-floating-point-numbers.rst | 6 ++-- doc/stdlib/base.rst | 34 +++++++------------ test/mpfr.jl | 6 ++-- test/rounding.jl | 12 +++---- 9 files changed, 48 insertions(+), 60 deletions(-) diff --git a/NEWS.md b/NEWS.md index 28c6541249148..87d5515f551fb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -49,6 +49,10 @@ Deprecated or removed * The `Stat` type is renamed `StatStruct` ([#4670]) + * `set_rounding`, `get_rounding` and `with_rounding` now take an additional + argument specifying the floating point type to which they apply. The old + behaviour and `[get/set/with]_bigfloat_rounding` functions are deprecated ([#5007]) + [#4775]: https://github.com/JuliaLang/julia/issues/4775 [#4870]: https://github.com/JuliaLang/julia/issues/4870 [#4766]: https://github.com/JuliaLang/julia/issues/4766 @@ -56,7 +60,7 @@ Deprecated or removed [#4759]: https://github.com/JuliaLang/julia/issues/4759 [#4819]: https://github.com/JuliaLang/julia/issues/4819 [#4670]: https://github.com/JuliaLang/julia/issues/4670 - +[#5007]: https://github.com/JuliaLang/julia/issues/5007 Julia v0.2.0 Release Notes diff --git a/base/deprecated.jl b/base/deprecated.jl index 63554120901b8..89311493d1ed1 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -359,5 +359,13 @@ const Stat = StatStruct export CharString const CharString = UTF32String +@deprecate set_rounding(r::RoundingMode) set_rounding(Float64,r) +@deprecate get_rounding() get_rounding(Float64) +@deprecate with_rounding(f::Function, r::RoundingMode) with_rounding(f::Function, Float64, r) + +@deprecate set_bigfloat_rounding(r::RoundingMode) set_rounding(BigFloat,r) +@deprecate get_bigfloat_rounding() get_rounding(BigFloat) +@deprecate with_bigfloat_rounding(f::Function, r::RoundingMode) with_rounding(f::Function, BigFloat, r) + # 0.3 discontinued functions diff --git a/base/exports.jl b/base/exports.jl index 5edfa1b3bbe07..ad2478ba0b431 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -842,9 +842,6 @@ export get_bigfloat_precision, set_bigfloat_precision, with_bigfloat_precision, - get_bigfloat_rounding, - set_bigfloat_rounding, - with_bigfloat_rounding, get_rounding, set_rounding, with_rounding, diff --git a/base/mpfr.jl b/base/mpfr.jl index d7e4c2717a6f5..62121162034ff 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -4,10 +4,7 @@ export BigFloat, get_bigfloat_precision, set_bigfloat_precision, - with_bigfloat_precision, - set_bigfloat_rounding, - get_bigfloat_rounding, - with_bigfloat_rounding + with_bigfloat_precision import Base: (*), +, -, /, <, <=, ==, >, >=, ^, besselj, besselj0, besselj1, bessely, @@ -20,7 +17,7 @@ import itrunc, eps, signbit, sin, cos, tan, sec, csc, cot, acos, asin, atan, cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, atan2, serialize, deserialize, inf, nan, hash, cbrt, typemax, typemin, - realmin, realmax + realmin, realmax, get_rounding, set_rounding import Base.Math.lgamma_r @@ -615,8 +612,8 @@ function from_mpfr(c::Integer) RoundingMode(c) end -get_bigfloat_rounding() = from_mpfr(ROUNDING_MODE[end]) -set_bigfloat_rounding(r::RoundingMode) = ROUNDING_MODE[end] = to_mpfr(r) +get_rounding(::Type{BigFloat}) = from_mpfr(ROUNDING_MODE[end]) +set_rounding(::Type{BigFloat},r::RoundingMode) = ROUNDING_MODE[end] = to_mpfr(r) function copysign(x::BigFloat, y::BigFloat) z = BigFloat() @@ -701,16 +698,6 @@ function with_bigfloat_precision(f::Function, precision::Integer) end end -function with_bigfloat_rounding(f::Function, rounding::RoundingMode) - old_rounding = get_bigfloat_rounding() - set_bigfloat_rounding(rounding) - try - return f() - finally - set_bigfloat_rounding(old_rounding) - end -end - function string(x::BigFloat) lng = 128 for i = 1:2 diff --git a/base/rounding.jl b/base/rounding.jl index 497323ad5fab2..2b3aa5756f7c7 100644 --- a/base/rounding.jl +++ b/base/rounding.jl @@ -46,16 +46,16 @@ function from_fenv(r::Integer) end end -set_rounding(r::RoundingMode) = ccall(:fesetround, Cint, (Cint,), to_fenv(r)) -get_rounding() = from_fenv(ccall(:fegetround, Cint, ())) +set_rounding{T<:Union(Float32,Float64)}(::Type{T},r::RoundingMode) = ccall(:fesetround, Cint, (Cint,), to_fenv(r)) +get_rounding{T<:Union(Float32,Float64)}(::Type{T}) = from_fenv(ccall(:fegetround, Cint, ())) -function with_rounding(f::Function, rounding::RoundingMode) - old_rounding = get_rounding() - set_rounding(rounding) +function with_rounding{T}(f::Function, ::Type{T}, rounding::RoundingMode) + old_rounding = get_rounding(T) + set_rounding(T,rounding) try return f() finally - set_rounding(old_rounding) + set_rounding(T,old_rounding) end end diff --git a/doc/manual/integers-and-floating-point-numbers.rst b/doc/manual/integers-and-floating-point-numbers.rst index 0e32d4e5b5e98..4d5446e7483dd 100644 --- a/doc/manual/integers-and-floating-point-numbers.rst +++ b/doc/manual/integers-and-floating-point-numbers.rst @@ -500,7 +500,7 @@ presented in the `IEEE 754 standard julia> 1.1 + 0.1 1.2000000000000002 - julia> with_rounding(RoundDown) do + julia> with_rounding(Float64,RoundDown) do 1.1 + 0.1 end 1.2 @@ -603,12 +603,12 @@ will take these changes in account: .. doctest:: - julia> with_bigfloat_rounding(RoundUp) do + julia> with_rounding(BigFloat,RoundUp) do BigFloat(1) + BigFloat("0.1") end 1.100000000000000000000000000000000000000000000000000000000000000000000000000003e+00 with 256 bits of precision - julia> with_bigfloat_rounding(RoundDown) do + julia> with_rounding(BigFloat,RoundDown) do BigFloat(1) + BigFloat("0.1") end 1.099999999999999999999999999999999999999999999999999999999999999999999999999986e+00 with 256 bits of precision diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index ad278f588dd18..80b9850a750ba 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -3135,22 +3135,26 @@ Numbers ``BigFloat(2.1)`` may not yield what you expect. You may prefer to initialize constants using strings, e.g., ``BigFloat("2.1")``. -.. function:: get_rounding() +.. function:: get_rounding(T) - Get the current floating point rounding mode. Valid modes are ``RoundNearest``, ``RoundToZero``, ``RoundUp`` and ``RoundDown``. + Get the current floating point rounding mode for type ``T``. Valid modes + are ``RoundNearest``, ``RoundToZero``, ``RoundUp``, ``RoundDown``, and + ``RoundFromZero`` (``BigFloat`` only). -.. function:: set_rounding(mode) +.. function:: set_rounding(T, mode) - Set the floating point rounding mode. See ``get_rounding`` for available modes + Set the rounding mode of floating point type ``T``. Note that this may + affect other types, for instance changing the rounding mode of ``Float64`` + will change the rounding mode of ``Float32``. See ``get_rounding`` for available modes -.. function:: with_rounding(f::Function,mode) +.. function:: with_rounding(f::Function, T, mode) - Change the floating point rounding mode for the duration of ``f``. It is logically equivalent to:: + Change the rounding mode of floating point type ``T`` for the duration of ``f``. It is logically equivalent to:: - old = get_rounding() - set_rounding(mode) + old = get_rounding(T) + set_rounding(T, mode) f() - set_rounding(old) + set_rounding(T, old) See ``get_rounding`` for available rounding modes. @@ -3240,18 +3244,6 @@ The `BigFloat` type implements arbitrary-precision floating-point aritmetic usin f() set_bigfloat_precision(old) -.. function:: get_bigfloat_rounding() - - Get the current BigFloat rounding mode. Valid modes are ``RoundNearest``, ``RoundToZero``, ``RoundUp``, ``RoundDown``, ``RoundFromZero`` - -.. function:: set_bigfloat_rounding(mode) - - Set the BigFloat rounding mode. See get_bigfloat_rounding for available modes - -.. function:: with_bigfloat_rounding(f::Function,mode) - - Change the BigFloat rounding mode for the duration of ``f``. See ``get_bigfloat_rounding`` for available rounding modes; see also ``with_bigfloat_precision``. - Random Numbers -------------- diff --git a/test/mpfr.jl b/test/mpfr.jl index 83424e0093d42..ffab08ae26b3c 100644 --- a/test/mpfr.jl +++ b/test/mpfr.jl @@ -82,14 +82,14 @@ z = BigFloat(30) # rounding modes with_bigfloat_precision(4) do # default mode is round to nearest - down, up = with_bigfloat_rounding(RoundNearest) do + down, up = with_rounding(BigFloat,RoundNearest) do BigFloat("0.0938"), BigFloat("0.102") end - with_bigfloat_rounding(RoundDown) do + with_rounding(BigFloat,RoundDown) do @test BigFloat(0.1) == down @test BigFloat(0.1) != up end - with_bigfloat_rounding(RoundUp) do + with_rounding(BigFloat,RoundUp) do @test BigFloat(0.1) != down @test BigFloat(0.1) == up end diff --git a/test/rounding.jl b/test/rounding.jl index 0194dd3567b36..d672d32250366 100644 --- a/test/rounding.jl +++ b/test/rounding.jl @@ -16,7 +16,7 @@ d = prevfloat(1.) @test b - a === c # RoundToZero -with_rounding(RoundToZero) do +with_rounding(Float64,RoundToZero) do @test a + b === d @test - a - b === -d @test a - b === -c @@ -30,7 +30,7 @@ end @test b - a == c # RoundUp -with_rounding(RoundUp) do +with_rounding(Float64,RoundUp) do @test a + b === 1. @test - a - b === -d @test a - b === -c @@ -38,7 +38,7 @@ with_rounding(RoundUp) do end # RoundDown -with_rounding(RoundDown) do +with_rounding(Float64,RoundDown) do @test a + b === d @test - a - b === -1. @test a - b === -c @@ -59,7 +59,7 @@ d32 = prevfloat(1.0f0) @test b32 - a32 === c32 # RoundToZero -with_rounding(RoundToZero) do +with_rounding(Float32,RoundToZero) do @test a32 + b32 === d32 @test - a32 - b32 === -d32 @test a32 - b32 === -c32 @@ -73,7 +73,7 @@ end @test b32 - a32 == c32 # RoundUp -with_rounding(RoundUp) do +with_rounding(Float32,RoundUp) do @test a32 + b32 === 1.0f0 @test - a32 - b32 === -d32 @test a32 - b32 === -c32 @@ -81,7 +81,7 @@ with_rounding(RoundUp) do end # RoundDown -with_rounding(RoundDown) do +with_rounding(Float32,RoundDown) do @test a32 + b32 === d32 @test - a32 - b32 === -1.0f0 @test a32 - b32 === -c32 From 897e889ae1a4a393ad6ac345e0bdf694c8d6eebc Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Mon, 16 Dec 2013 12:14:38 -0500 Subject: [PATCH 29/89] Avoid BigInt dependency in 128-bit parsing via div op in parseint. This is all a bit of a tangled mess because of all the LLVM code gen bugs for large integer operations. Hopefully in the future this can all just go away once LLVM actually fixes these bugs. Fixes #5174. --- base/string.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/string.jl b/base/string.jl index 368f9c79a6fb4..4c4956d1ca798 100644 --- a/base/string.jl +++ b/base/string.jl @@ -1471,7 +1471,8 @@ function parseint_nocheck{T<:Integer}(::Type{T}, s::String, base::Int, a::Int) sgn, base, i = parseint_preamble(T<:Signed,s,base) c, i = parseint_next(s,i) base = convert(T,base) - m::T = div(typemax(T)-base+1,base) + ## FIXME: remove 128-bit specific code once 128-bit div doesn't rely on BigInt + m::T = T===Uint128 || T===Int128 ? typemax(T) : div(typemax(T)-base+1,base) n::T = 0 while n <= m d::T = '0' <= c <= '9' ? c-'0' : From b94f2d2ce2d3badaeb784b75030fd0d080aff180 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 16 Dec 2013 13:52:06 -0500 Subject: [PATCH 30/89] fix #5165 jl_isbits is not sufficient to store something unboxed; you must also have jl_is_leaf_type, to make sure a tag won't be needed at run time --- src/codegen.cpp | 8 ++++---- test/core.jl | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index f5fa95e39e47f..bb8b2b7f6703a 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -886,9 +886,9 @@ static bool is_getfield_nonallocating(jl_datatype_t *ty, jl_value_t *fld) static bool jltupleisbits(jl_value_t *jt, bool allow_unsized) { if (!jl_is_tuple(jt)) - return jl_isbits(jt) && (allow_unsized || - ((jl_is_bitstype(jt) && jl_datatype_size(jt) > 0) || - (jl_is_datatype(jt) && jl_tuple_len(((jl_datatype_t*)jt)->names)>0))); + return jl_isbits(jt) && jl_is_leaf_type(jt) && (allow_unsized || + ((jl_is_bitstype(jt) && jl_datatype_size(jt) > 0) || + (jl_is_datatype(jt) && jl_tuple_len(((jl_datatype_t*)jt)->names)>0))); size_t ntypes = jl_tuple_len(jt); if (ntypes == 0) return allow_unsized; @@ -1433,7 +1433,7 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs, size_t i; for(i=0; i < nargs; i++) { jl_value_t *it = (jl_value_t*)expr_type(args[i+1],ctx); - if (!jl_isbits(it)) + if (!(jl_isbits(it) && jl_is_leaf_type(it))) break; } if (i >= nargs) { diff --git a/test/core.jl b/test/core.jl index f8bfcaf5bb57b..228a14792951e 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1180,3 +1180,12 @@ end # issue #5150 f5150(T) = Array(Rational{T},1) @test typeof(f5150(Int)) === Array{Rational{Int},1} + +# issue #5165 +bitstype 64 T5165{S} +make_t(x::Int64) = Base.box(T5165{Nothing}, Base.unbox(Int64, x)) +xs5165 = T5165[make_t(1)] +b5165 = IOBuffer() +for x in xs5165 + println(b5165, x) # segfaulted +end From 5dbc59e23a25f68497394345f4206f08e469ff94 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 16 Dec 2013 14:19:54 -0500 Subject: [PATCH 31/89] Implement lexcmp for Complex --- base/complex.jl | 6 ++++++ test/complex.jl | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/base/complex.jl b/base/complex.jl index bd9de333c3188..858bc15c117b4 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -654,3 +654,9 @@ function atanh{T<:FloatingPoint}(z::Complex{T}) complex(ξ, η) end atanh(z::Complex) = atanh(float(z)) + +function lexcmp(a::Complex, b::Complex) + c = cmp(real(a), real(b)) + c == 0 || return c + cmp(imag(a), imag(b)) +end diff --git a/test/complex.jl b/test/complex.jl index 0cf0fe0b2f62d..983ac2a78ebac 100644 --- a/test/complex.jl +++ b/test/complex.jl @@ -592,6 +592,12 @@ @test isequal(atan(complex( NaN, NaN)),complex( NaN, NaN)) +# lexcmp +@test lexcmp(1.0-1.0im, 1.0+0.0im) == -1 +@test lexcmp(0.0+0.0im, 0.0+0.0im) == 0 +@test lexcmp(1.0-1.0im, 0.0+0.0im) == 1 + + # misc. @test complex(1//2,1//3)^2 === complex(5//36, 1//3) From 6512939bd5631d810d9c260e90ca9d86c618e5fd Mon Sep 17 00:00:00 2001 From: James Porter Date: Mon, 16 Dec 2013 00:33:06 -0600 Subject: [PATCH 32/89] Allow tuples as type parameters. --- src/jltypes.c | 14 ++++++++++++-- test/core.jl | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/jltypes.c b/src/jltypes.c index 6e288e471857e..d21f103b5a19d 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -1447,8 +1447,18 @@ int jl_types_equal_generic(jl_value_t *a, jl_value_t *b, int useenv) static int valid_type_param(jl_value_t *v) { - // TODO: maybe more things - return jl_is_type(v) || jl_is_long(v) || jl_is_symbol(v) || jl_is_typevar(v) || jl_is_bool(v); + if (jl_is_tuple(v)) { + size_t i; + size_t l = jl_tuple_len(v); + for(i=0; i < l; i++) { + if (!valid_type_param(jl_tupleref(v,i))) + return 0; + } + return 1; + } else { + // TODO: maybe more things + return jl_is_type(v) || jl_is_long(v) || jl_is_symbol(v) || jl_is_typevar(v) || jl_is_bool(v); + } } jl_value_t *jl_apply_type_(jl_value_t *tc, jl_value_t **params, size_t n) diff --git a/test/core.jl b/test/core.jl index 228a14792951e..60e6f74e8c443 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1181,6 +1181,7 @@ end f5150(T) = Array(Rational{T},1) @test typeof(f5150(Int)) === Array{Rational{Int},1} + # issue #5165 bitstype 64 T5165{S} make_t(x::Int64) = Base.box(T5165{Nothing}, Base.unbox(Int64, x)) @@ -1189,3 +1190,26 @@ b5165 = IOBuffer() for x in xs5165 println(b5165, x) # segfaulted end + +# support tuples as type parameters + +type TupleParam{P} + x::Bool +end + +function tupledispatch(a::TupleParam{(1,:a)}) + a.x +end + +let + # tuples can be used as type params + t1 = TupleParam{(1,:a)}(true) + t2 = TupleParam{(1,:b)}(true) + + # tuple type params can't contain invalid type params + @test_throws t3 = TupleParam{(1,"nope")}(true) + + # dispatch works properly + @test tupledispatch(t1) == true + @test_throws tupledispatch(t2) +end From 7637526dc72262d79da5bb9b28c4403efcd79806 Mon Sep 17 00:00:00 2001 From: James Porter Date: Mon, 16 Dec 2013 13:52:20 -0600 Subject: [PATCH 33/89] Update manual section on type parameters. Indicating that bools and tuples are allowable. --- doc/manual/types.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/manual/types.rst b/doc/manual/types.rst index 8ffdeeea5bc1a..60902a02b5006 100644 --- a/doc/manual/types.rst +++ b/doc/manual/types.rst @@ -1,7 +1,7 @@ .. _man-types: ********* - Types + Types ********* Type systems have traditionally fallen into two quite different camps: @@ -61,7 +61,7 @@ Julia's type system that should be mentioned up front are: - Only values, not variables, have types — variables are simply names bound to values. - Both abstract and concrete types can be paramaterized by other types - and by certain other values (currently integers and symbols). + and by certain other values (currently integers, symbols, bools, and tuples thereof). Type parameters may be completely omitted when they do not need to be referenced or restricted. @@ -1153,4 +1153,3 @@ If you apply ``super`` to other type objects (or non-type objects), a julia> super((Float64,Int64)) ERROR: no method super(Type{(Float64,Int64)}) - From 2b2b42ccb228ba99548b0aa2778507b8428d2a70 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Mon, 16 Dec 2013 17:56:30 -0500 Subject: [PATCH 34/89] digits: make it work for BigInts (by making ndigits0z work for them) Also, add test for Project Euler problem #16. --- base/gmp.jl | 4 +++- test/bigint.jl | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/base/gmp.jl b/base/gmp.jl index fcea16d70bf35..0b77724bd5b97 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -7,7 +7,7 @@ import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), ($), ndigits, promote_rule, rem, show, isqrt, string, isprime, powermod, widemul, sum, trailing_zeros, trailing_ones, count_ones, base, parseint, serialize, deserialize, bin, oct, dec, hex, isequal, invmod, - prevpow2, nextpow2 + prevpow2, nextpow2, ndigits0z type BigInt <: Integer alloc::Cint @@ -406,6 +406,8 @@ function base(b::Integer, n::BigInt) end ndigits(x::BigInt, base::Integer=10) = ccall((:__gmpz_sizeinbase,:libgmp), Culong, (Ptr{BigInt}, Int32), &x, base) +ndigits0z(x::BigInt, base::Integer=10) = x == 0 ? 0 : ndigits(x) + isprime(x::BigInt, reps=25) = ccall((:__gmpz_probab_prime_p,:libgmp), Cint, (Ptr{BigInt}, Cint), &x, reps) > 0 widemul(x::BigInt, y::BigInt) = x*y diff --git a/test/bigint.jl b/test/bigint.jl index 7d9c330f9ef64..4862d91b00c23 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -262,3 +262,5 @@ let seek(b,0) @test deserialize(b) == n end + +@test sum(digits(big(2)^1000)) == 1366 From 751176b49546390782a17d58072fbcec217e9d1c Mon Sep 17 00:00:00 2001 From: "David A. van Leeuwen" Date: Tue, 17 Dec 2013 12:02:19 +0100 Subject: [PATCH 35/89] Changed 'U' to ``:U`` in docs for chol(). Same for ``:L`` --- doc/stdlib/linalg.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/stdlib/linalg.rst b/doc/stdlib/linalg.rst index c49abcb5d1a76..5d8150247efe3 100644 --- a/doc/stdlib/linalg.rst +++ b/doc/stdlib/linalg.rst @@ -57,11 +57,11 @@ Linear algebra functions in Julia are largely implemented by calling functions f .. function:: chol(A, [LU]) -> F - Compute Cholesky factorization of a symmetric positive-definite matrix ``A`` and return the matrix ``F``. If ``LU`` is ``L`` (Lower), ``A = L*L'``. If ``LU`` is ``U`` (Upper), ``A = R'*R``. + Compute Cholesky factorization of a symmetric positive-definite matrix ``A`` and return the matrix ``F``. If ``LU`` is ``:L`` (Lower), ``A = L*L'``. If ``LU`` is ``:U`` (Upper), ``A = R'*R``. .. function:: cholfact(A, [LU]) -> Cholesky - Compute the Cholesky factorization of a dense symmetric positive-definite matrix ``A`` and return a ``Cholesky`` object. ``LU`` may be 'L' for using the lower part or 'U' for the upper part. The default is to use 'U'. The triangular matrix can be obtained from the factorization ``F`` with: ``F[:L]`` and ``F[:U]``. The following functions are available for ``Cholesky`` objects: ``size``, ``\``, ``inv``, ``det``. A ``LAPACK.PosDefException`` error is thrown in case the matrix is not positive definite. + Compute the Cholesky factorization of a dense symmetric positive-definite matrix ``A`` and return a ``Cholesky`` object. ``LU`` may be ``:L`` for using the lower part or ``:U`` for the upper part. The default is to use ``:U``. The triangular matrix can be obtained from the factorization ``F`` with: ``F[:L]`` and ``F[:U]``. The following functions are available for ``Cholesky`` objects: ``size``, ``\``, ``inv``, ``det``. A ``LAPACK.PosDefException`` error is thrown in case the matrix is not positive definite. .. function:: cholfact(A, [ll]) -> CholmodFactor @@ -73,7 +73,7 @@ Linear algebra functions in Julia are largely implemented by calling functions f .. function:: cholpfact(A, [LU]) -> CholeskyPivoted - Compute the pivoted Cholesky factorization of a symmetric positive semi-definite matrix ``A`` and return a ``CholeskyPivoted`` object. ``LU`` may be 'L' for using the lower part or 'U' for the upper part. The default is to use 'U'. The triangular factors contained in the factorization ``F`` can be obtained with ``F[:L]`` and ``F[:U]``, whereas the permutation can be obtained with ``F[:P]`` or ``F[:p]``. + Compute the pivoted Cholesky factorization of a symmetric positive semi-definite matrix ``A`` and return a ``CholeskyPivoted`` object. ``LU`` may be ``:L`` for using the lower part or ``:U`` for the upper part. The default is to use ``:U``. The triangular factors contained in the factorization ``F`` can be obtained with ``F[:L]`` and ``F[:U]``, whereas the permutation can be obtained with ``F[:P]`` or ``F[:p]``. The following functions are available for ``CholeskyPivoted`` objects: ``size``, ``\``, ``inv``, ``det``. A ``LAPACK.RankDeficientException`` error is thrown in case the matrix is rank deficient. From 56753b6e135522785dfc199fc4c3b3829b5b0aa1 Mon Sep 17 00:00:00 2001 From: timholy Date: Tue, 17 Dec 2013 05:14:20 -0600 Subject: [PATCH 36/89] Fix #5180 --- base/subarray.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base/subarray.jl b/base/subarray.jl index efe2b02ca90b5..6f187999db200 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -53,7 +53,7 @@ end # if `I` were a vector, index_ranges would do the following: # j = length(I) -# while j > 0 && isa(j[0], Int) +# while j > 0 && isa(I[j], Int) # j -= 1 # end # for i = 1:j @@ -127,9 +127,9 @@ function slice(A::SubArray, i::RangeIndex...) slice(A.parent, tuple(newindexes...)) end -# Generic fallback for Colon translation -sub(A::AbstractArray, I...) = sub(A, ntuple(length(I), i-> isa(I[i], Colon) ? (1:size(A,i)) : I[i])...) -slice(A::AbstractArray, I...) = slice(A, ntuple(length(I), i-> isa(I[i], Colon) ? (1:size(A,i)) : I[i])...) +# Colon translation +sub(A::AbstractArray, I::Union(RangeIndex, Colon)...) = sub(A, ntuple(length(I), i-> isa(I[i], Colon) ? (1:size(A,i)) : I[i])...) +slice(A::AbstractArray, I::Union(RangeIndex, Colon)...) = slice(A, ntuple(length(I), i-> isa(I[i], Colon) ? (1:size(A,i)) : I[i])...) ### rename the old slice function ### From b555993481f848cae7bd9d5c1c86112dac33ceac Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Tue, 17 Dec 2013 22:31:59 -0500 Subject: [PATCH 37/89] Project Euler: decent basic functionality tests & fun to write. This seems like a pretty good way to get better test coverage of miscellaneous functionality, especially of the mathematical kind. That's how I discovered digits didn't work for BigInts yesterday: the test introduced was actually problem 16. --- test/Makefile | 2 +- test/bigint.jl | 2 - test/euler.jl | 467 +++++++++++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 19 +- 4 files changed, 478 insertions(+), 12 deletions(-) create mode 100644 test/euler.jl diff --git a/test/Makefile b/test/Makefile index 2c503fce875b5..0e990bc7a845d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -6,7 +6,7 @@ TESTS = all core keywordargs numbers strings unicode collections hashing \ math functional bigint sorting statistics spawn parallel arpack file \ git pkg resolve suitesparse complex version pollfd mpfr broadcast \ socket floatapprox priorityqueue readdlm regex float16 combinatorics \ - sysinfo rounding ranges mod2pi + sysinfo rounding ranges mod2pi euler default: all diff --git a/test/bigint.jl b/test/bigint.jl index 4862d91b00c23..7d9c330f9ef64 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -262,5 +262,3 @@ let seek(b,0) @test deserialize(b) == n end - -@test sum(digits(big(2)^1000)) == 1366 diff --git a/test/euler.jl b/test/euler.jl new file mode 100644 index 0000000000000..4d492b8d1f866 --- /dev/null +++ b/test/euler.jl @@ -0,0 +1,467 @@ +## Project Euler +# +# problems: http://projecteuler.net/problems +# solutions: https://code.google.com/p/projecteuler-solutions/wiki/ProjectEulerSolutions + +#1: 233168 +@test sum(filter(n->(n%3==0)|(n%5==0),1:999)) == 233168 + +#2: 4613732 +function euler2(n) + t, i, j = 0, 1, 2 + while j <= n + t += j + i, j = j, i+j + i, j = j, i+j + i, j = j, i+j + end + return t +end +@test euler2(4000000) == 4613732 + +#3: 6857 +@test maximum(keys(factor(600851475143))) == 6857 + +#4: 906609 +function euler4(n) + m = 1 + for a=10^n-1:-1:10^(n-1), + b=10^n-1:-1:max(a,-fld(-m,a)) + p = a*b + d = digits(p) + d == reverse(d) || continue + m = max(m,p) + end + return m +end +@test euler4(3) == 906609 + +#5: 232792560 +#6: 25164150 +#7: 104743 +#8: 40824 +#9: 31875000 +#10: 142913828922 +#11: 70600674 +#12: 76576500 +#13: 5537376230 +#14: 837799 +#15: 137846528820 + +#16: 1366 +@test sum(digits(big(2)^1000)) == 1366 + +#17: 21124 +#18: 1074 +#19: 171 +#20: 648 +#21: 31626 +#22: 871198282 +#23: 4179871 +#24: 2783915460 +#25: 4782 +#26: 983 +#27: -59231 +#28: 669171001 +#29: 9183 +#30: 443839 +#31: 73682 +#32: 45228 +#33: 100 +#34: 40730 +#35: 55 +#36: 872187 +#37: 748317 +#38: 932718654 +#39: 840 +#40: 210 +#41: 7652413 +#42: 162 +#43: 16695334890 +#44: 5482660 +#45: 1533776805 +#46: 5777 +#47: 134043 +#48: 9110846700 +#49: 296962999629 +#50: 997651 +#51: 121313 +#52: 142857 +#53: 4075 +#54: 376 +#55: 249 +#56: 972 +#57: 153 +#58: 26241 +#59: 107359 +#60: 26033 +#61: 28684 +#62: 127035954683 +#63: 49 +#64: 1322 +#65: 272 +#66: 661 +#67: 7273 +#68: 6531031914842725 +#69: 510510 +#70: 8319823 +#71: 428570 +#72: 303963552391 +#73: 7295372 +#74: 402 +#75: 161667 +#76: 190569291 +#77: 71 +#78: 55374 +#79: 73162890 +#80: 40886 +#81: 427337 +#82: 260324 +#83: 425185 +#84: 101524 +#85: 2772 +#86: 1818 +#87: 1097343 +#88: 7587457 +#89: 743 +#90: 1217 +#91: 14234 +#92: 8581146 +#93: 1258 +#94: 518408346 +#95: 14316 +#96: 24702 +#97: 8739992577 +#98: 18769 +#99: 709 +#100: 756872327473 +#101: 37076114526 +#102: 228 +#103: 20313839404245 +#104: 329468 +#105: 73702 +#106: 21384 +#107: 259679 +#108: 180180 +#109: 38182 +#110: 9350130049860600 +#111: 612407567715 +#112: 1587000 +#113: 51161058134250 +#114: 16475640049 +#115: 168 +#116: 20492570929 +#117: 100808458960497 +#118: 44680 +#119: 248155780267521 +#120: 333082500 +#121: 2269 +#122: 1582 +#123: 21035 +#124: 21417 +#125: 2906969179 +#126: 18522 +#127: 18407904 +#128: 14516824220 +#129: 1000023 +#130: 149253 +#131: 173 +#132: 843296 +#133: 453647705 +#134: 18613426663617118 +#135: 4989 +#136: 2544559 +#137: 1120149658760 +#138: 1118049290473932 +#139: 10057761 +#140: 5673835352990 +#141: 878454337159 +#142: 1006193 +#143: 30758397 +#144: 354 +#145: 608720 +#146: 676333270 +#147: 846910284 +#148: 2129970655314432 +#149: 52852124 +#150: -271248680 +#151: 0.464399 +#152: 301 +#153: 17971254122360635 +#154: 479742450 +#155: 3857447 +#156: 21295121502550 +#157: 53490 +#158: 409511334375 +#159: 14489159 +#160: 16576 +#161: 20574308184277971 +#162: 3D58725572C62302 +#163: 343047 +#164: 378158756814587 +#165: 2868868 +#166: 7130034 +#167: 3916160068885 +#168: 59206 +#169: 178653872807 +#170: 9857164023 +#171: 142989277 +#172: 227485267000992000 +#173: 1572729 +#174: 209566 +#175: 1,13717420,8 +#176: 96818198400000 +#177: 129325 +#178: 126461847755 +#179: 986262 +#180: 285196020571078987 +#181: 83735848679360680 +#182: 399788195976 +#183: 48861552 +#184: 1725323624056 +#185: 4640261571849533 +#186: 2325629 +#187: 17427258 +#188: 95962097 +#189: 10834893628237824 +#190: 371048281 +#191: 1918080160 +#192: 57060635927998347 +#193: 684465067343069 +#194: 61190912 +#195: 75085391 +#196: 322303240771079935 +#197: 1.710637717 +#198: 52374425 +#199: 0.00396087 +#200: 229161792008 +#201: 115039000 +#202: 1209002624 +#203: 34029210557338 +#204: 2944730 +#205: 0.5731441 +#206: 1389019170 +#207: 44043947822 +#208: 331951449665644800 +#209: 15964587728784 +#210: 1598174770174689458 +#211: 1922364685 +#212: 328968937309 +#213: 330.721154 +#214: 1677366278943 +#215: 806844323190414 +#216: 5437849 +#217: 6273134 +#218: 0 +#219: 64564225042 +#220: 139776,963904 +#221: 1884161251122450 +#222: 1590933 +#223: 61614848 +#224: 4137330 +#225: 2009 +#226: 0.11316017 +#227: 3780.618622 +#228: 86226 +#229: 11325263 +#230: 850481152593119296 +#231: 7526965179680 +#232: 0.83648556 +#233: 271204031455541309 +#234: 1259187438574927161 +#235: 1.002322108633 +#236: 123/59 +#237: 15836928 +#238: 9922545104535661 +#239: 0.001887854841 +#240: 7448717393364181966 +#241: 482316491800641154 +#242: 997104142249036713 +#243: 892371480 +#244: 96356848 +#245: 288084712410001 +#246: 810834388 +#247: 782252 +#248: 23507044290 +#249: 9275262564250418 +#250: 1425480602091519 +#251: 18946051 +#252: 104924.0 +#253: 11.492847 +#254: 8184523820510 +#255: 4.4474011180 +#256: 85765680 +#257: 139012411 +#258: 12747994 +#259: 20101196798 +#260: 167542057 +#261: 238890850232021 +#262: 2531.205 +#263: 2039506520 +#264: 2816417.1055 +#265: 209110240768 +#266: 1096883702440585 +#267: 0.999992836187 +#268: 785478606870985 +#269: 1311109198529286 +#270: 82282080 +#271: 4617456485273129588 +#272: 8495585919506151122 +#273: 2032447591196869022 +#274: 1601912348822 +#275: 15030564 +#276: 5777137137739632912 +#277: 1125977393124310 +#278: 1228215747273908452 +#279: 416577688 +#280: 430.088247 +#281: 1485776387445623 +#282: 1098988351 +#283: 28038042525570324 +#284: 5a411d7b +#285: 157055.80999 +#286: 52.6494571953 +#287: 313135496 +#288: 605857431263981935 +#289: 6567944538 +#290: 20444710234716473 +#291: 4037526 +#292: 3600060866 +#293: 2209 +#294: 789184709 +#295: 4884650818 +#296: 1137208419 +#297: 2252639041804718029 +#298: 1.76882294 +#299: 549936643 +#300: 8.0540771484375 +#301: 2178309 +#302: 1170060 +#303: 1111981904675169 +#304: 283988410192 +#305: 18174995535140 +#306: 852938 +#307: 0.7311720251 +#308: 1539669807660924 +#309: 210139 +#310: 2586528661783 +#311: 2466018557 +#312: 324681947 +#313: 2057774861813004 +#314: 132.52756426 +#315: 13625242 +#316: 542934735751917735 +#317: 1856532.8455 +#318: 709313889 +#319: 268457129 +#320: 278157919195482643 +#321: 2470433131948040 +#322: 999998760323313995 +#323: 6.3551758451 +#324: 96972774 +#325: 54672965 +#326: 1966666166408794329 +#327: 34315549139516 +#328: 260511850222 +#329: 199740353/29386561536000 +#330: 15955822 +#331: 467178235146843549 +#332: 2717.751525 +#333: 3053105 +#334: 150320021261690835 +#335: 5032316 +#336: CAGBIHEFJDK +#337: 85068035 +#338: 15614292 +#339: 19823.542204 +#340: 291504964 +#341: 56098610614277014 +#342: 5943040885644 +#343: 269533451410884183 +#344: 65579304332 +#345: 13938 +#346: 336108797689259276 +#347: 11109800204052 +#348: 1004195061 +#349: 115384615384614952 +#350: 84664213 +#351: 11762187201804552 +#352: 378563.260589 +#353: 1.2759860331 +#354: 58065134 +#355: 1726545007 +#356: 28010159 +#357: 1739023853137 +#358: 3284144505 +#359: 40632119 +#360: 878825614395267072 +#361: 178476944 +#362: 457895958010 +#363: 0.0000372091 +#364: 44855254 +#365: 162619462356610313 +#366: 88351299 +#367: 48271207 +#368: 253.6135092068 +#369: 862400558448 +#370: 41791929448408 +#371: 40.66368097 +#372: 301450082318807027 +#373: 727227472448913 +#374: 334420941 +#375: 7435327983715286168 +#376: 973059630185670 +#377: 732385277 +#378: 147534623725724718 +#379: 132314136838185 +#380: 6.3202e25093 +#381: 139602943319822 +#382: 697003956 +#383: 22173624649806 +#384: 3354706415856332783 +#385: 3776957309612153700 +#386: 528755790 +#387: 696067597313468 +#388: 831907372805129931 +#389: 2406376.3623 +#390: 2919133642971 +#391: 61029882288 +#392: 3.1486734435 +#393: 112398351350823112 +#394: 3.2370342194 +#395: 28.2453753155 +#396: 173214653 +#397: 141630459461893728 +#398: 2010.59096 +#399: 1508395636674243,6.5e27330467 +#400: 438505383468410633 +#401: 281632621 +#402: 356019862 +#403: 18224771 +#404: 1199215615081353 +#405: 237696125 +#406: 36813.12757207 +#407: 39782849136421 +#408: 299742733 +#409: 253223948 +#410: +#411: 9936352 +#412: 38788800 +#413: 3079418648040719 +#414: +#415: +#416: +#417: 446572970925740 +#418: 1177163565297340320 +#419: 998567458,1046245404,43363922 +#420: 145159332 +#421: +#422: +#423: +#424: +#425: 46479497324 +#426: +#427: +#428: +#429: 98792821 +#430: 5000624921.38 diff --git a/test/runtests.jl b/test/runtests.jl index 68397af2f1790..a3169de5d2d1e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,12 +1,13 @@ -testnames = ["core", "keywordargs", "numbers", "strings", "unicode", - "collections", "hashing", "remote", "iobuffer", "arrayops", - "linalg", "blas", "fft", "dsp", "sparse", "bitarray", - "random", "math", "functional", "bigint", "sorting", - "statistics", "spawn", "parallel", "priorityqueue", - "arpack", "file", "suitesparse", "version", - "resolve", "pollfd", "mpfr", "broadcast", "complex", - "socket", "floatapprox", "readdlm", "regex", "float16", - "combinatorics", "sysinfo", "rounding", "ranges", "mod2pi"] +testnames = [ + "core", "keywordargs", "numbers", "strings", "unicode", + "collections", "hashing", "remote", "iobuffer", "arrayops", "linalg", + "blas", "fft", "dsp", "sparse", "bitarray", "random", "math", + "functional", "bigint", "sorting", "statistics", "spawn", "parallel", + "priorityqueue", "arpack", "file", "suitesparse", "version", + "resolve", "pollfd", "mpfr", "broadcast", "complex", "socket", + "floatapprox", "readdlm", "regex", "float16", "combinatorics", + "sysinfo", "rounding", "ranges", "mod2pi", "euler" +] tests = ARGS==["all"] ? testnames : ARGS From f37e4c52e5bc833e7c0844bd873399603a78e471 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Tue, 17 Dec 2013 23:14:14 -0500 Subject: [PATCH 38/89] Projet Euler 5: lcm(1:20) == 232792560 It's handy to be able to take the gcd/lcm of a collection of integers. Also, code golf in your own language feels a bit cheap. --- base/intfuncs.jl | 3 +++ test/euler.jl | 2 ++ 2 files changed, 5 insertions(+) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 447e6ca6fe628..265ddb091a73a 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -51,6 +51,9 @@ lcm(a::Integer, b::Integer) = lcm(promote(a,b)...) gcd(a::Integer, b::Integer...) = gcd(a, gcd(b...)) lcm(a::Integer, b::Integer...) = lcm(a, lcm(b...)) +gcd{T<:Integer}(abc::AbstractArray{T}) = gcd(abc...) +lcm{T<:Integer}(abc::AbstractArray{T}) = lcm(abc...) + # return (gcd(a,b),x,y) such that ax+by == gcd(a,b) function gcdx{T<:Integer}(a::T, b::T) s0, s1 = one(T), zero(T) diff --git a/test/euler.jl b/test/euler.jl index 4d492b8d1f866..c4246ff53b532 100644 --- a/test/euler.jl +++ b/test/euler.jl @@ -37,6 +37,8 @@ end @test euler4(3) == 906609 #5: 232792560 +@test lcm(1:20) == 232792560 + #6: 25164150 #7: 104743 #8: 40824 From 253875a580a013b57d84e1df4c8600304a3e6eb7 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Tue, 17 Dec 2013 23:58:23 -0500 Subject: [PATCH 39/89] Project Euler 6-11. --- test/euler.jl | 94 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 17 deletions(-) diff --git a/test/euler.jl b/test/euler.jl index c4246ff53b532..d6ee66949d83d 100644 --- a/test/euler.jl +++ b/test/euler.jl @@ -8,14 +8,14 @@ #2: 4613732 function euler2(n) - t, i, j = 0, 1, 2 - while j <= n - t += j - i, j = j, i+j - i, j = j, i+j - i, j = j, i+j - end - return t + t, i, j = 0, 1, 2 + while j <= n + t += j + i, j = j, i+j + i, j = j, i+j + i, j = j, i+j + end + return t end @test euler2(4000000) == 4613732 @@ -24,15 +24,15 @@ end #4: 906609 function euler4(n) - m = 1 - for a=10^n-1:-1:10^(n-1), - b=10^n-1:-1:max(a,-fld(-m,a)) - p = a*b - d = digits(p) - d == reverse(d) || continue - m = max(m,p) - end - return m + m = 1 + for a=10^n-1:-1:10^(n-1), + b=10^n-1:-1:max(a,-fld(-m,a)) + p = a*b + d = digits(p) + d == reverse(d) || continue + m = max(m,p) + end + return m end @test euler4(3) == 906609 @@ -40,11 +40,71 @@ end @test lcm(1:20) == 232792560 #6: 25164150 +@test sum(1:100)^2 - sum((1:100).^2) == 25164150 + #7: 104743 +euler7(n) = primes(ifloor(n*log(n*log(n))))[n] +@test euler7(10001) == 104743 + #8: 40824 +function euler8(n,m) + d = digits(n) + maximum([prod(d[k:k+m-1]) for k=1:length(d)-m+1]) +end +let n = 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450 + @test euler8(n,5) == 40824 +end + #9: 31875000 +function euler9(n) + for a = 1:n, + b = 1:n-a + c = n-a-b + a^2 + b^2 == c^2 && return a*b*c + end +end +@test euler9(1000) == 31875000 + #10: 142913828922 +@test sum(primes(2000000)) == 142913828922 + #11: 70600674 +function euler11(grid,n) + m = typemin(eltype(grid)) + for i = n:size(grid,1)-n+1, + j = n:size(grid,2)-n+1, + di = -1:1, dj = -1:1 + di == dj == 0 && continue + idx = sub2ind(size(grid),Range(i,di,n),Range(j,dj,n)) + m = max(m,prod(grid[idx])) + end + return m +end +let grid = [ + 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 + 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 + 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 + 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 + 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 + 24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50 + 32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70 + 67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21 + 24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72 + 21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95 + 78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92 + 16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57 + 86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58 + 19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40 + 04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66 + 88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69 + 04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36 + 20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16 + 20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54 + 01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48 +] + @test euler11(grid,4) == 70600674 +end + #12: 76576500 #13: 5537376230 #14: 837799 From 6376cc28474d88e90a3bd00b5d32faefe36212fa Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 18 Dec 2013 00:16:34 -0500 Subject: [PATCH 40/89] gcd, lcm on collection: use reduce instead of splatting. --- base/intfuncs.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 265ddb091a73a..66af6fbded201 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -51,8 +51,8 @@ lcm(a::Integer, b::Integer) = lcm(promote(a,b)...) gcd(a::Integer, b::Integer...) = gcd(a, gcd(b...)) lcm(a::Integer, b::Integer...) = lcm(a, lcm(b...)) -gcd{T<:Integer}(abc::AbstractArray{T}) = gcd(abc...) -lcm{T<:Integer}(abc::AbstractArray{T}) = lcm(abc...) +gcd{T<:Integer}(abc::AbstractArray{T}) = reduce(gcd,abc) +lcm{T<:Integer}(abc::AbstractArray{T}) = reduce(lcm,abc) # return (gcd(a,b),x,y) such that ax+by == gcd(a,b) function gcdx{T<:Integer}(a::T, b::T) From 6854a616bd257be5b08ac07cc7aa1dfb554fb6ff Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 18 Dec 2013 01:18:14 -0500 Subject: [PATCH 41/89] tests/euler.jl: 13, 14 & 20. --- test/euler.jl | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/test/euler.jl b/test/euler.jl index d6ee66949d83d..81821a8a7cf00 100644 --- a/test/euler.jl +++ b/test/euler.jl @@ -106,8 +106,134 @@ let grid = [ end #12: 76576500 + #13: 5537376230 +let nums = [ + 37107287533902102798797998220837590246510135740250 + 46376937677490009712648124896970078050417018260538 + 74324986199524741059474233309513058123726617309629 + 91942213363574161572522430563301811072406154908250 + 23067588207539346171171980310421047513778063246676 + 89261670696623633820136378418383684178734361726757 + 28112879812849979408065481931592621691275889832738 + 44274228917432520321923589422876796487670272189318 + 47451445736001306439091167216856844588711603153276 + 70386486105843025439939619828917593665686757934951 + 62176457141856560629502157223196586755079324193331 + 64906352462741904929101432445813822663347944758178 + 92575867718337217661963751590579239728245598838407 + 58203565325359399008402633568948830189458628227828 + 80181199384826282014278194139940567587151170094390 + 35398664372827112653829987240784473053190104293586 + 86515506006295864861532075273371959191420517255829 + 71693888707715466499115593487603532921714970056938 + 54370070576826684624621495650076471787294438377604 + 53282654108756828443191190634694037855217779295145 + 36123272525000296071075082563815656710885258350721 + 45876576172410976447339110607218265236877223636045 + 17423706905851860660448207621209813287860733969412 + 81142660418086830619328460811191061556940512689692 + 51934325451728388641918047049293215058642563049483 + 62467221648435076201727918039944693004732956340691 + 15732444386908125794514089057706229429197107928209 + 55037687525678773091862540744969844508330393682126 + 18336384825330154686196124348767681297534375946515 + 80386287592878490201521685554828717201219257766954 + 78182833757993103614740356856449095527097864797581 + 16726320100436897842553539920931837441497806860984 + 48403098129077791799088218795327364475675590848030 + 87086987551392711854517078544161852424320693150332 + 59959406895756536782107074926966537676326235447210 + 69793950679652694742597709739166693763042633987085 + 41052684708299085211399427365734116182760315001271 + 65378607361501080857009149939512557028198746004375 + 35829035317434717326932123578154982629742552737307 + 94953759765105305946966067683156574377167401875275 + 88902802571733229619176668713819931811048770190271 + 25267680276078003013678680992525463401061632866526 + 36270218540497705585629946580636237993140746255962 + 24074486908231174977792365466257246923322810917141 + 91430288197103288597806669760892938638285025333403 + 34413065578016127815921815005561868836468420090470 + 23053081172816430487623791969842487255036638784583 + 11487696932154902810424020138335124462181441773470 + 63783299490636259666498587618221225225512486764533 + 67720186971698544312419572409913959008952310058822 + 95548255300263520781532296796249481641953868218774 + 76085327132285723110424803456124867697064507995236 + 37774242535411291684276865538926205024910326572967 + 23701913275725675285653248258265463092207058596522 + 29798860272258331913126375147341994889534765745501 + 18495701454879288984856827726077713721403798879715 + 38298203783031473527721580348144513491373226651381 + 34829543829199918180278916522431027392251122869539 + 40957953066405232632538044100059654939159879593635 + 29746152185502371307642255121183693803580388584903 + 41698116222072977186158236678424689157993532961922 + 62467957194401269043877107275048102390895523597457 + 23189706772547915061505504953922979530901129967519 + 86188088225875314529584099251203829009407770775672 + 11306739708304724483816533873502340845647058077308 + 82959174767140363198008187129011875491310547126581 + 97623331044818386269515456334926366572897563400500 + 42846280183517070527831839425882145521227251250327 + 55121603546981200581762165212827652751691296897789 + 32238195734329339946437501907836945765883352399886 + 75506164965184775180738168837861091527357929701337 + 62177842752192623401942399639168044983993173312731 + 32924185707147349566916674687634660915035914677504 + 99518671430235219628894890102423325116913619626622 + 73267460800591547471830798392868535206946944540724 + 76841822524674417161514036427982273348055556214818 + 97142617910342598647204516893989422179826088076852 + 87783646182799346313767754307809363333018982642090 + 10848802521674670883215120185883543223812876952786 + 71329612474782464538636993009049310363619763878039 + 62184073572399794223406235393808339651327408011116 + 66627891981488087797941876876144230030984490851411 + 60661826293682836764744779239180335110989069790714 + 85786944089552990653640447425576083659976645795096 + 66024396409905389607120198219976047599490197230297 + 64913982680032973156037120041377903785566085089252 + 16730939319872750275468906903707539413042652315011 + 94809377245048795150954100921645863754710598436791 + 78639167021187492431995700641917969777599028300699 + 15368713711936614952811305876380278410754449733078 + 40789923115535562561142322423255033685442488917353 + 44889911501440648020369068063960672322193204149535 + 41503128880339536053299340368006977710650566631954 + 81234880673210146739058568557934581403627822703280 + 82616570773948327592232845941706525094512325230608 + 22918802058777319719839450180888072429661980811197 + 77158542502016545090413245809786882778948721859617 + 72107838435069186155435662884062257473692284509516 + 20849603980134001723930671666823555245252804609722 + 53503534226472524250874054075591789781264330331690 +] + @test sum(digits(sum(nums))[end-9:end].*10.^(0:9)) == 5537376230 +end + #14: 837799 +function euler14(m) + c = zeros(Int,m) + c[1] = 1 + for n = 2:m + nʹ, d = n, 0 + while nʹ > length(c) || c[nʹ] == 0 + nʹ = iseven(nʹ) ? nʹ>>1 : 3nʹ+1 + d += 1 + end + d += c[nʹ] + while n > length(c) || c[n] == 0 + n <= length(c) && (c[n] = d) + n = iseven(n) ? n>>1 : 3n+1 + d -= 1 + end + end + indmax(c) +end +@test euler14(999999) == 837799 + #15: 137846528820 #16: 1366 @@ -116,7 +242,10 @@ end #17: 21124 #18: 1074 #19: 171 + #20: 648 +@test sum(digits(factorial(big(100)))) == 648 + #21: 31626 #22: 871198282 #23: 4179871 From 95e08874b935f81fb62442b921f96a7edf04c1b6 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 18 Dec 2013 01:33:40 -0500 Subject: [PATCH 42/89] test/euler.jl: 24 --- test/euler.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/euler.jl b/test/euler.jl index 81821a8a7cf00..90fd923f3eb14 100644 --- a/test/euler.jl +++ b/test/euler.jl @@ -57,9 +57,7 @@ end #9: 31875000 function euler9(n) - for a = 1:n, - b = 1:n-a - c = n-a-b + for a = 1:n, b = 1:n-a, c = n-a-b a^2 + b^2 == c^2 && return a*b*c end end @@ -249,7 +247,10 @@ end #21: 31626 #22: 871198282 #23: 4179871 + #24: 2783915460 +@test nthperm!([0:9],1000000) == [2,7,8,3,9,1,5,4,6,0] + #25: 4782 #26: 983 #27: -59231 From 5d80bf8d745d68612764fd8c538d0c51abc3619e Mon Sep 17 00:00:00 2001 From: timholy Date: Wed, 18 Dec 2013 05:53:07 -0600 Subject: [PATCH 43/89] Add summary of tools for enhancing performance --- doc/manual/performance-tips.rst | 19 +++++++++++++++++++ doc/stdlib/profile.rst | 12 +++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/doc/manual/performance-tips.rst b/doc/manual/performance-tips.rst index 92ec65a623041..b371d7b8c9adb 100644 --- a/doc/manual/performance-tips.rst +++ b/doc/manual/performance-tips.rst @@ -359,3 +359,22 @@ These are some minor points that might help in tight inner loops. try to rewrite code to use ``abs2`` instead of ``abs`` for complex arguments. - Use ``div(x,y)`` for truncating division of integers instead of ``trunc(x/y)``, and ``fld(x,y)`` instead of ``floor(x/y)``. + +Tools +----- + +Julia includes some tools that may help you improve the performance of your code: + +- :ref:`stdlib-profiling` allows you to measure the performance of + your running code and identify lines that serve as bottlenecks. + +- Unexpectedly-large memory allocations---as reported by ``@time``, + ``@allocated``, or the profiler (through calls to the + garbage-collection routines)---hint that there might be issues with + your code. If you don't see another reason for the allocations, + suspect a type problem. + +- Using ``code_typed()`` on your function can help identify sources of + type problems. Look particularly for variables that, contrary to + your intentions, are inferred to be ``Union`` types. Such problems + can usually be fixed using the tips above. diff --git a/doc/stdlib/profile.rst b/doc/stdlib/profile.rst index b156a4cb723ec..e293b76878910 100644 --- a/doc/stdlib/profile.rst +++ b/doc/stdlib/profile.rst @@ -1,3 +1,5 @@ +.. _stdlib-profiling: + Profiling ========= @@ -58,7 +60,9 @@ Now we're ready to profile this function:: julia> @profile myfunc() -Now let's see the results:: +To see the profiling results, there is a `graphical browser +`_ available, but here +we'll use the text-based display that comes with the standard library:: julia> Profile.print() 23 client.jl; _start; line: 373 @@ -146,8 +150,10 @@ In general, if you have ``N`` samples collected at a line, you can expect an uncertainty on the order of ``sqrt(N)`` (barring other sources of noise, like how busy the computer is with other tasks). The major exception to this rule is garbage-collection, which runs -infrequently but tends to be quite expensive. Below you'll see how you -can detect such events. +infrequently but tends to be quite expensive. (Since julia's garbage +collector is written in C, such events can be detected using the +``C=true`` output mode described below, or by using `ProfileView +`_.) This illustrates the default "tree" dump; an alternative is the "flat" dump, which accumulates counts independent of their nesting:: From 31c8388aa79366b1591464d5654ea0e3d2c2b518 Mon Sep 17 00:00:00 2001 From: timholy Date: Wed, 18 Dec 2013 09:50:51 -0600 Subject: [PATCH 44/89] Performance tips: add pre-allocation --- doc/manual/performance-tips.rst | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/doc/manual/performance-tips.rst b/doc/manual/performance-tips.rst index b371d7b8c9adb..7c7457b293382 100644 --- a/doc/manual/performance-tips.rst +++ b/doc/manual/performance-tips.rst @@ -337,6 +337,69 @@ of the ``Matrix`` and fills it one column at a time. Additionally, our rule of thumb that the first element to appear in a slice expression should be coupled with the inner-most loop. +Pre-allocating outputs +---------------------- + +If your function returns an Array or some other complex +type, it may have to allocate memory. Unfortunately, oftentimes +allocation and its converse, garbage collection, are substantial +bottlenecks. + +Sometimes you can circumvent the need to allocate memory on each +function call by pre-allocating the output. As a +trivial example, compare + + function xinc(x) + return [x, x+1, x+2] + end + + function loopinc() + y = 0 + for i = 1:10^7 + ret = xinc(i) + y += ret[2] + end + y + end + +with + + function xinc!{T}(ret::AbstractVector{T}, x::T) + ret[1] = x + ret[2] = x+1 + ret[3] = x+2 + nothing + end + + function loopinc_prealloc() + ret = Array(Int, 3) + y = 0 + for i = 1:10^7 + xinc!(ret, i) + y += ret[2] + end + y + end + +Timing results: + + julia> @time loopinc() + elapsed time: 1.955026528 seconds (1279975584 bytes allocated) + 50000015000000 + + julia> @time loopinc_prealloc() + elapsed time: 0.078639163 seconds (144 bytes allocated) + 50000015000000 + +Pre-allocation has other advantages, for example by allowing the +caller to control the "output" type from an algorithm. In the example +above, we could have passed a ``SubArray`` rather than an ``Array``, +had we so desired. + +Taken to its extreme, pre-allocation can make your code uglier, so +performance measurements and some judgment may be required. + + Fix deprecation warnings ------------------------ From edb26e56ac489c37383c69b17e400d6297249269 Mon Sep 17 00:00:00 2001 From: timholy Date: Wed, 18 Dec 2013 09:58:47 -0600 Subject: [PATCH 45/89] docs: fix formatting issues with 31c8388aa79366b1591464d5654ea0e3d2c2b518 --- doc/manual/performance-tips.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/manual/performance-tips.rst b/doc/manual/performance-tips.rst index 7c7457b293382..b8f74fac172f7 100644 --- a/doc/manual/performance-tips.rst +++ b/doc/manual/performance-tips.rst @@ -348,6 +348,7 @@ bottlenecks. Sometimes you can circumvent the need to allocate memory on each function call by pre-allocating the output. As a trivial example, compare +:: function xinc(x) return [x, x+1, x+2] @@ -363,6 +364,7 @@ trivial example, compare end with +:: function xinc!{T}(ret::AbstractVector{T}, x::T) ret[1] = x @@ -381,7 +383,7 @@ with y end -Timing results: +Timing results:: julia> @time loopinc() elapsed time: 1.955026528 seconds (1279975584 bytes allocated) From 38c4c7c3b9229955550779ef39e63caaa8ed1c9f Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 18 Dec 2013 12:29:46 -0500 Subject: [PATCH 46/89] NEWS updates --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index 99ff960c9db49..2dfd5cb42ef93 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,9 @@ New language features * Greatly enhanced performance for passing and returning tuples ([#4042]). + * Tuples (of integers, symbols, or bools) can now be used as type + parameters ([#5164]). + New library functions --------------------- @@ -44,6 +47,8 @@ Library improvements * `rand` now supports arbitrary `Ranges` arguments ([#5059]). + * `modpi` function ([#4799]). + Deprecated or removed --------------------- From 0b31aeb843f8b6c55ab9f626fc95cd78effab0d4 Mon Sep 17 00:00:00 2001 From: Adrian Lopez Date: Wed, 18 Dec 2013 18:32:01 +0100 Subject: [PATCH 47/89] Package libuv-julia-dev doesn't exists --- contrib/vagrant/Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/vagrant/Vagrantfile b/contrib/vagrant/Vagrantfile index 5e17fe05b7539..c406fc826c8eb 100644 --- a/contrib/vagrant/Vagrantfile +++ b/contrib/vagrant/Vagrantfile @@ -18,7 +18,7 @@ apt-get update -qq -y apt-get install python-software-properties -y add-apt-repository ppa:staticfloat/julia-deps -y apt-get update -qq -y -apt-get install g++ git make patchelf gfortran llvm-3.3 libsuitesparse-dev libncurses5-dev libopenblas-dev liblapack-dev libarpack2-dev libfftw3-dev libgmp-dev libpcre3-dev libunwind7-dev libreadline-dev libdouble-conversion-dev libopenlibm-dev librmath-dev libuv-julia-dev libmpfr-dev -y +apt-get install g++ git make patchelf gfortran llvm-3.3 libsuitesparse-dev libncurses5-dev libopenblas-dev liblapack-dev libarpack2-dev libfftw3-dev libgmp-dev libpcre3-dev libunwind7-dev libreadline-dev libdouble-conversion-dev libopenlibm-dev librmath-dev libmpfr-dev -y SCRIPT Vagrant.configure("2") do |config| From 971c2f05ad2ff1e82c8cb6859294d4b0ccadeaea Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 18 Dec 2013 13:13:12 -0500 Subject: [PATCH 48/89] NEWS: modpi => mod2pi --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2dfd5cb42ef93..364785987ca7f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -47,7 +47,7 @@ Library improvements * `rand` now supports arbitrary `Ranges` arguments ([#5059]). - * `modpi` function ([#4799]). + * `mod2pi` function ([#4799], [#4862]). Deprecated or removed --------------------- From 1687c76c2195320b83397044fa16b00036e2b252 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 18 Dec 2013 13:53:23 -0500 Subject: [PATCH 49/89] add generic fallback for Blas.LinAlg.axpy\!, make sure it always returns y rather than a pointer --- base/linalg.jl | 1 + base/linalg/blas.jl | 7 ++++--- base/linalg/generic.jl | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/base/linalg.jl b/base/linalg.jl index 28e7bdeeb32da..7c1d6fa34a1a9 100644 --- a/base/linalg.jl +++ b/base/linalg.jl @@ -35,6 +35,7 @@ export Diagonal, # Functions + axpy!, bkfact, bkfact!, check_blas, diff --git a/base/linalg/blas.jl b/base/linalg/blas.jl index 77233c057277d..5a6d3d4a7c5a8 100644 --- a/base/linalg/blas.jl +++ b/base/linalg/blas.jl @@ -37,7 +37,7 @@ export const libblas = Base.libblas_name -import ..LinAlg: BlasFloat, BlasChar, BlasInt, blas_int, DimensionMismatch, chksquare +import ..LinAlg: BlasFloat, BlasChar, BlasInt, blas_int, DimensionMismatch, chksquare, axpy! # Level 1 ## copy @@ -163,12 +163,12 @@ for (fname, elty) in ((:daxpy_,:Float64), end end end -function axpy!{T,Ta<:Number}(alpha::Ta, x::Array{T}, y::Array{T}) +function axpy!{T<:BlasFloat,Ta<:Number}(alpha::Ta, x::Array{T}, y::Array{T}) length(x)==length(y) || throw(DimensionMismatch("")) axpy!(length(x), convert(T,alpha), x, 1, y, 1) end -function axpy!{T,Ta<:Number,Ti<:Integer}(alpha::Ta, x::Array{T}, rx::Union(Range1{Ti},Range{Ti}), +function axpy!{T<:BlasFloat,Ta<:Number,Ti<:Integer}(alpha::Ta, x::Array{T}, rx::Union(Range1{Ti},Range{Ti}), y::Array{T}, ry::Union(Range1{Ti},Range{Ti})) length(rx)==length(ry) || throw(DimensionMismatch("")) @@ -177,6 +177,7 @@ function axpy!{T,Ta<:Number,Ti<:Integer}(alpha::Ta, x::Array{T}, rx::Union(Range throw(BoundsError()) end axpy!(length(rx), convert(T, alpha), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry)) + y end ## iamax diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index ee20586a4516b..775489ca9e2e3 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -203,3 +203,24 @@ function peakflops(n::Integer=2000; parallel::Bool=false) parallel ? sum(pmap(peakflops, [ n for i in 1:nworkers()])) : (2*n^3/t) end +# BLAS-like in-place y=alpha*x+y function (see also the version in blas.jl +# for BlasFloat Arrays) +function axpy!(alpha, x::AbstractArray, y::AbstractArray) + n = length(x) + n==length(y) || throw(DimensionMismatch("")) + for i = 1:n + @inbounds y[i] += alpha * x[i] + end + y +end +function axpy!{Ti<:Integer,Tj<:Integer}(alpha, x::AbstractArray, rx::AbstractArray{Ti}, y::AbstractArray, ry::AbstractArray{Tj}) + length(x)==length(y) || throw(DimensionMismatch("")) + if minimum(rx) < 1 || maximum(rx) > length(x) || minimum(ry) < 1 || maximum(ry) > length(y) || length(rx) != length(ry) + throw(BoundsError()) + end + for i = 1:length(rx) + @inbounds y[ry[i]] += alpha * x[rx[i]] + end + y +end + From bdd0c7eb17c5e41036056fcd7be31784ef0eb8ba Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 18 Dec 2013 19:49:39 -0500 Subject: [PATCH 50/89] improve complex inv. fixes #5188 also simplify division code a bit --- base/complex.jl | 103 ++++++++++++++++++++++-------------------------- test/complex.jl | 3 ++ 2 files changed, 51 insertions(+), 55 deletions(-) diff --git a/base/complex.jl b/base/complex.jl index 858bc15c117b4..d7b1b61c59df6 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -126,6 +126,7 @@ conj(z::Complex) = complex(real(z),-imag(z)) abs(z::Complex) = hypot(real(z), imag(z)) abs2(z::Complex) = real(z)*real(z) + imag(z)*imag(z) inv(z::Complex) = conj(z)/abs2(z) +inv{T<:Integer}(z::Complex{T}) = inv(float(z)) sign(z::Complex) = z/abs(z) (-)(::ImaginaryUnit) = complex(0, -1) @@ -151,6 +152,7 @@ sign(z::Complex) = z/abs(z) *(w::Complex, z::ImaginaryUnit) = complex(-imag(w), real(w)) /(z::Number, w::Complex) = z*inv(w) +/(a::Real , w::Complex) = a*inv(w) /(z::Complex, x::Real) = complex(real(z)/x, imag(z)/x) function /(a::Complex, b::Complex) @@ -174,77 +176,68 @@ function /(a::Complex, b::Complex) end end -/(a::Real, b::Complex) = - real(convert(promote_type(typeof(a),typeof(b)),a)) / - convert(promote_type(typeof(a),typeof(b)),b) -function /{T<:Real}(a::T, b::Complex{T}) - bre = real(b); bim = imag(b) - if abs(bre) <= abs(bim) - if isinf(bre) && isinf(bim) - r = sign(bre)/sign(bim) - else - r = bre / bim - end - den = bim + r*bre - complex(a*r/den, -a/den) - else - if isinf(bre) && isinf(bim) - r = sign(bim)/sign(bre) - else - r = bim / bre - end - den = bre + r*bim - complex(a/den, -a*r/den) - end -end -function /(a::Complex{Float64}, b::Complex{Float64}) - r,i = robust_cdiv(real(a), imag(a), real(b), imag(b)) - Complex{Float64}(r,i) -end -# robust_cdiv performs complex division in real arithmetic -# the first step is to scale variables if appropriate -# then do calculations in way that avoids over/underflow (subfuncs 1 and 2) -# then undo the scaling +inv{T<:Union(Float16,Float32)}(z::Complex{T}) = + oftype(z, conj(complex128(z))/abs2(complex128(z))) + +# robust complex division for double precision +# the first step is to scale variables if appropriate ,then do calculations +# in a way that avoids over/underflow (subfuncs 1 and 2), then undo the scaling. # scaling variable s and other techniques # based on arxiv.1210.4539 # a + i*b # p + i*q = --------- # c + i*d -function robust_cdiv{T<:Float64}(a::T,b::T,c::T,d::T) - const half::T = 0.5 - const two::T = 2.0 - const ab::T = max(abs(a), abs(b)) - const cd::T = max(abs(c), abs(d)) - const ov::T = realmax(T) - const un::T = realmin(T) - const ϵ::T = eps(T) - const bs=two/(ϵ*ϵ) - s::T = 1.0 +function /(z::Complex128, w::Complex128) + a, b = reim(z); c, d = reim(w) + half = 0.5 + two = 2.0 + ab = max(abs(a), abs(b)) + cd = max(abs(c), abs(d)) + ov = realmax(a) + un = realmin(a) + ϵ = eps(Float64) + bs = two/(ϵ*ϵ) + s = 1.0 ab >= half*ov && (a=half*a; b=half*b; s=two*s ) # scale down a,b cd >= half*ov && (c=half*c; d=half*d; s=s*half) # scale down c,d ab <= un*two/ϵ && (a=a*bs; b=b*bs; s=s/bs ) # scale up a,b cd <= un*two/ϵ && (c=c*bs; d=d*bs; s=s*bs ) # scale up c,d abs(d)<=abs(c) ? ((p,q)=robust_cdiv1(a,b,c,d) ) : ((p,q)=robust_cdiv1(b,a,d,c); q=-q) - return p*s,q*s # undo scaling -end -function robust_cdiv1{T<:Float64}(a::T,b::T,c::T,d::T) - const one::T = 1.0 - const r::T=d/c - const t::T=one/(c+d*r) - p::T=robust_cdiv2(a,b,c,d,r,t) - q::T=robust_cdiv2(b,-a,c,d,r,t) + return Complex128(p*s,q*s) # undo scaling +end +function robust_cdiv1(a::Float64, b::Float64, c::Float64, d::Float64) + r = d/c + t = 1.0/(c+d*r) + p = robust_cdiv2(a,b,c,d,r,t) + q = robust_cdiv2(b,-a,c,d,r,t) return p,q end -function robust_cdiv2{T<:Float64}(a::T,b::T,c::T,d::T,r::T,t::T) - const zero::T = 0.0 - if r != zero - const br::T = b*r - return (br != zero ? (a+br)*t : a*t + (b*t)*r) +function robust_cdiv2(a::Float64, b::Float64, c::Float64, d::Float64, r::Float64, t::Float64) + if r != 0 + br = b*r + return (br != 0 ? (a+br)*t : a*t + (b*t)*r) else return (a + d*(b/c)) * t end end - + +function inv(w::Complex128) + c, d = reim(w) + half = 0.5 + two = 2.0 + cd = max(abs(c), abs(d)) + ov = realmax(c) + un = realmin(c) + ϵ = eps(Float64) + bs = two/(ϵ*ϵ) + s = 1.0 + cd >= half*ov && (c=half*c; d=half*d; s=s*half) # scale down c,d + cd <= un*two/ϵ && (c=c*bs; d=d*bs; s=s*bs ) # scale up c,d + abs(d)<=abs(c) ? ((p,q)=robust_cdiv1(1.0,0.0,c,d)) : + ((p,q)=robust_cdiv1(0.0,1.0,d,c); q=-q) + return Complex128(p*s,q*s) # undo scaling +end + function ssqs{T<:FloatingPoint}(x::T, y::T) k::Int = 0 ρ = x*x + y*y diff --git a/test/complex.jl b/test/complex.jl index 983ac2a78ebac..1a3b6c9f27907 100644 --- a/test/complex.jl +++ b/test/complex.jl @@ -647,3 +647,6 @@ function cdiv_test(a,b) end @test cdiv_test(complex(1//2, 3//4), complex(17//13, 4//5)) @test cdiv_test(complex(1,2), complex(8997,2432)) + +# inv +@test inv(1e300+0im) == 1e-300 - 0.0im From 47a1ae5bc20b5efcdebad6f92eef139411ef82e1 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 18 Dec 2013 22:06:45 -0500 Subject: [PATCH 51/89] fix help for nextind and prevind. fixes #5156 --- doc/stdlib/base.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 8553f44ddc476..8756225c96c73 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -1044,12 +1044,12 @@ Strings .. function:: nextind(str, i) - Get the next valid string index after ``i``. Returns ``endof(str)+1`` at - the end of the string. + Get the next valid string index after ``i``. Returns a value greater than ``endof(str)`` + at or after the end of the string. .. function:: prevind(str, i) - Get the previous valid string index before ``i``. Returns ``0`` at + Get the previous valid string index before ``i``. Returns a value less than ``1`` at the beginning of the string. .. function:: randstring(len) From 2fffb9bb0e9dd2cb9116b07bc5a381f013075112 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 19 Dec 2013 01:54:07 -0500 Subject: [PATCH 52/89] factor common code out of the two permutedims! --- base/bitarray.jl | 109 ++++++++++++++++------------------------------- base/exports.jl | 1 + 2 files changed, 38 insertions(+), 72 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 6a37abb17ed78..5dcb5f6a6e03d 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -2125,6 +2125,41 @@ ctranspose(B::BitArray) = transpose(B) ## Permute array dims ## +function permute_one_dim(ivars, stridenames) + len = length(ivars) + counts = { symbol(string("count",i)) for i=1:len} + toReturn = cell(len+1,2) + for i = 1:length(toReturn) + toReturn[i] = nothing + end + + tmp = counts[end] + toReturn[len+1] = quote + ind = 1 + $tmp = $(stridenames[len]) + end + + #inner most loop + toReturn[1] = quote + P[ind] = B[+($(counts...))+offset] + ind+=1 + $(counts[1]) += $(stridenames[1]) + end + for i = 1:len-1 + tmp = counts[i] + val = i + toReturn[(i+1)] = quote + $tmp = $(stridenames[val]) + end + tmp2 = counts[i+1] + val = i+1 + toReturn[(i+1)+(len+1)] = quote + $tmp2 += $(stridenames[val]) + end + end + toReturn +end + let permutedims_cache = nothing, stridenames::Array{Any,1} = {} global permutedims! function permutedims!(P::BitArray,B::BitArray, perm) @@ -2155,46 +2190,11 @@ function permutedims!(P::BitArray,B::BitArray, perm) B = B.parent end - function permute_one_dim(ivars) - len = length(ivars) - counts = { symbol(string("count",i)) for i=1:len} - toReturn = cell(len+1,2) - for i = 1:length(toReturn) - toReturn[i] = nothing - end - - tmp = counts[end] - toReturn[len+1] = quote - ind = 1 - $tmp = $(stridenames[len]) - end - - #inner most loop - toReturn[1] = quote - P[ind] = B[+($(counts...))+offset] - ind+=1 - $(counts[1]) += $(stridenames[1]) - end - for i = 1:len-1 - tmp = counts[i] - val = i - toReturn[(i+1)] = quote - $tmp = $(stridenames[val]) - end - tmp2 = counts[i+1] - val = i+1 - toReturn[(i+1)+(len+1)] = quote - $tmp2 += $(stridenames[val]) - end - end - toReturn - end - if is(permutedims_cache,nothing) permutedims_cache = Dict() end - gen_cartesian_map(permutedims_cache, permute_one_dim, ranges, + gen_cartesian_map(permutedims_cache, iv->permute_one_dim(iv,stridenames), ranges, tuple(:B, :P, :perm, :offset, stridenames[1:ndimsB]...), B, P, perm, offset, strides...) @@ -2228,46 +2228,11 @@ function permutedims!(P::Array,B::StridedArray, perm) B = B.parent end - function permute_one_dim(ivars) - len = length(ivars) - counts = { symbol(string("count",i)) for i=1:len} - toReturn = cell(len+1,2) - for i = 1:length(toReturn) - toReturn[i] = nothing - end - - tmp = counts[end] - toReturn[len+1] = quote - ind = 1 - $tmp = $(stridenames[len]) - end - - #inner most loop - toReturn[1] = quote - P[ind] = B[+($(counts...))+offset] - ind+=1 - $(counts[1]) += $(stridenames[1]) - end - for i = 1:len-1 - tmp = counts[i] - val = i - toReturn[(i+1)] = quote - $tmp = $(stridenames[val]) - end - tmp2 = counts[i+1] - val = i+1 - toReturn[(i+1)+(len+1)] = quote - $tmp2 += $(stridenames[val]) - end - end - toReturn - end - if is(permutedims_cache,nothing) permutedims_cache = Dict() end - gen_cartesian_map(permutedims_cache, permute_one_dim, ranges, + gen_cartesian_map(permutedims_cache, iv->permute_one_dim(iv,stridenames), ranges, tuple(:B, :P, :perm, :offset, stridenames[1:ndimsB]...), B, P, perm, offset, strides...) diff --git a/base/exports.jl b/base/exports.jl index 48395d6e953a1..baa3850b6d270 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -534,6 +534,7 @@ export permutations, permute!, permutedims, + permutedims!, prod, promote_shape, randcycle, From 1be8d500c2479ca85edfe6f1903f2ffef7ef1965 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 19 Dec 2013 01:57:03 -0500 Subject: [PATCH 53/89] small formatting changes --- base/combinatorics.jl | 4 +--- doc/stdlib/base.rst | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/base/combinatorics.jl b/base/combinatorics.jl index f2773c2862e86..7a2875c3f4e56 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -417,7 +417,6 @@ function nextsetpartition(s::AbstractVector, a, b, n, m) end - const _nsetpartitions = (Int=>Int)[] function nsetpartitions(n::Int) if n < 0 @@ -451,7 +450,7 @@ start(p::FixedSetPartitions) = (n = length(p.s);m=p.m; (vcat(ones(Int, n-m),1:m) done(p::FixedSetPartitions, s) = !isempty(s) && s[1][1] > 1 next(p::FixedSetPartitions, s) = nextfixedsetpartition(p.s,p.m, s...) -function nextfixedsetpartition(s::AbstractVector,m, a, b, n) +function nextfixedsetpartition(s::AbstractVector, m, a, b, n) function makeparts(s, a) part = [ similar(s,0) for k = 1:m ] for i = 1:n @@ -492,7 +491,6 @@ function nextfixedsetpartition(s::AbstractVector,m, a, b, n) end return (part, (a,b,n)) - end function nfixedsetpartitions(n::Int,m::Int) diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 44323554623f8..48b4ed6f7c730 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -3810,14 +3810,14 @@ Combinatorics The number of partitions to generete can be efficiently computed using ``length(partitions(array))``. -.. function:: partitions(array,m) +.. function:: partitions(array, m) - Generate all set partitions of the elements of an array into exactly, - m subsets, represented as arrays of arrays. Because the number of + Generate all set partitions of the elements of an array into exactly m + subsets, represented as arrays of arrays. Because the number of partitions can be very large, this function returns an iterator object. Use ``collect(partitions(array,m))`` to get an array of all partitions. The number of partitions into m subsets is equal to the Stirling number - of the second kind and can be efficiently computed using + of the second kind and can be efficiently computed using ``length(partitions(array,m))``. Statistics From fcd61d38aca9cf47e0f5d0dd0dcc158dfdcf47e1 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 19 Dec 2013 02:04:09 -0500 Subject: [PATCH 54/89] close #5006 --- doc/manual/strings.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/manual/strings.rst b/doc/manual/strings.rst index 646de9ceffd2f..e53b1a354a396 100644 --- a/doc/manual/strings.rst +++ b/doc/manual/strings.rst @@ -184,13 +184,16 @@ You can do comparisons and a limited amount of arithmetic with String Basics ------------- -Here a variable is initialized with a simple string literal: +String literals are delimited by double quotes or triple double quotes: .. doctest:: julia> str = "Hello, world.\n" "Hello, world.\n" + julia> """Contains "quote" characters""" + "Contains \"quote\" characters" + If you want to extract a character from a string, you index into it: .. doctest:: @@ -249,7 +252,7 @@ You can also extract a substring using range indexing: julia> str[4:9] "lo, wo" -Note the distinction between ``str[k]`` and ``str[k:k]``: +Notice that the expressions ``str[k]`` and ``str[k:k]`` do not give the same result: .. doctest:: From 524e305872f4a0946a283bc75308c13462432285 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 19 Dec 2013 02:07:44 -0500 Subject: [PATCH 55/89] WINDOWS: add SEH tables for JIT code --- src/codegen.cpp | 6 +++++ src/debuginfo.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++ src/init.c | 2 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index bb8b2b7f6703a..b41dc9eb0ddf7 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -9,6 +9,8 @@ */ #if defined(_OS_WINDOWS_) #include +#define WIN32_LEAN_AND_MEAN +#include #if defined(_COMPILER_INTEL_) #include #else @@ -23,6 +25,7 @@ #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/JITEventListener.h" +#include "llvm/ExecutionEngine/JITMemoryManager.h" #include "llvm/PassManager.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Passes.h" @@ -3829,6 +3832,9 @@ extern "C" void jl_init_codegen(void) std::vector attrvec (mattr, mattr+2); jl_ExecutionEngine = EngineBuilder(jl_Module) .setEngineKind(EngineKind::JIT) +#if defined(_OS_WINDOWS_) + .setJITMemoryManager(new JITMemoryManagerWin()) +#endif .setTargetOptions(options) .setMAttrs(attrvec) .create(); diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index f2d36989c4cfc..52b2eac0713bc 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -19,6 +19,21 @@ class JuliaJITEventListener: public JITEventListener { FuncInfo tmp = {&F, Size, Details.LineStarts}; info[(size_t)(Code)] = tmp; +#if defined(_OS_WINDOWS_) + PRUNTIME_FUNCTION tbl = (PRUNTIME_FUNCTION)(((uintptr_t)Code + Size + 3)&~(uintptr_t)3); + uint8_t *UnwindData = (uint8_t*)((((uintptr_t)&tbl[1])+3)&~(uintptr_t)3); + RUNTIME_FUNCTION fn = {0,(DWORD)Size,(DWORD)(intptr_t)(UnwindData-(uint8_t*)Code)}; + tbl[0] = fn; + UnwindData[0] = 0x20; // version info, UNW_FLAG_NHANDLER + UnwindData[1] = 4; // size of prolog (bytes) + UnwindData[2] = 2; // count of unwind codes (slots) + UnwindData[3] = 0x50; // frame register (rbp) = rsp + UnwindData[4] = 0x01; // first instruction + UnwindData[5] = 0x05; // push RBP + UnwindData[6] = 0x04; // second instruction + UnwindData[7] = 0x10; // mov RBP, RSP + RtlAddFunctionTable(tbl,1,(DWORD64)Code); +#endif } std::map& getMap() @@ -83,3 +98,49 @@ void getFunctionInfo(const char **name, int *line, const char **filename, size_t } } } + +#if defined(_OS_WINDOWS_) +class JITMemoryManagerWin : public JITMemoryManager { +private: + JITMemoryManager *JMM; +public: + JITMemoryManagerWin() : JITMemoryManager() { + JMM = JITMemoryManager::CreateDefaultMemManager(); + } + virtual void setMemoryWritable() { return JMM->setMemoryWritable(); } + virtual void setMemoryExecutable() { return JMM->setMemoryExecutable(); } + virtual void setPoisonMemory(bool poison) { return JMM->setPoisonMemory(poison); } + virtual void AllocateGOT() { JMM->AllocateGOT(); HasGOT = true; } + virtual uint8_t *getGOTBase() const { return JMM->getGOTBase(); } + virtual uint8_t *startFunctionBody(const Function *F, + uintptr_t &ActualSize) { ActualSize += 16; uint8_t *ret = JMM->startFunctionBody(F,ActualSize); ActualSize -= 16; return ret; } + virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize, + unsigned Alignment) { return JMM->allocateStub(F,StubSize,Alignment); } + virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart, + uint8_t *FunctionEnd) { return JMM->endFunctionBody(F,FunctionStart,FunctionEnd+16); } + virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) { return JMM->allocateSpace(Size,Alignment); } + virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) { return JMM->allocateGlobal(Size,Alignment); } + virtual void deallocateFunctionBody(void *Body) { return JMM->deallocateFunctionBody(Body); } + virtual uint8_t* startExceptionTable(const Function* F, + uintptr_t &ActualSize) { return JMM->startExceptionTable(F,ActualSize); } + virtual void endExceptionTable(const Function *F, uint8_t *TableStart, + uint8_t *TableEnd, uint8_t* FrameRegister) { return JMM->endExceptionTable(F,TableStart,TableEnd,FrameRegister); } + virtual void deallocateExceptionTable(void *ET) { return JMM->deallocateExceptionTable(ET); } + virtual bool CheckInvariants(std::string &str) { return JMM->CheckInvariants(str); } + virtual size_t GetDefaultCodeSlabSize() { return JMM->GetDefaultCodeSlabSize(); } + virtual size_t GetDefaultDataSlabSize() { return JMM->GetDefaultDataSlabSize(); } + virtual size_t GetDefaultStubSlabSize() { return JMM->GetDefaultStubSlabSize(); } + virtual unsigned GetNumCodeSlabs() { return JMM->GetNumCodeSlabs(); } + virtual unsigned GetNumDataSlabs() { return JMM->GetNumDataSlabs(); } + virtual unsigned GetNumStubSlabs() { return JMM->GetNumStubSlabs(); } + + virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, + unsigned SectionID) { return JMM->allocateCodeSection(Size,Alignment,SectionID); } + virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, + unsigned SectionID, bool IsReadOnly) { return JMM->allocateDataSection(Size,Alignment,SectionID,IsReadOnly); } + virtual void *getPointerToNamedFunction(const std::string &Name, + bool AbortOnFailure = true) { return JMM->getPointerToNamedFunction(Name,AbortOnFailure); } + virtual bool applyPermissions(std::string *ErrMsg = 0) { return JMM->applyPermissions(ErrMsg); } + virtual void registerEHFrames(StringRef SectionData) { return JMM->registerEHFrames(SectionData); } +}; +#endif diff --git a/src/init.c b/src/init.c index 969ff3e1382c9..7d8f3a2ee20ee 100644 --- a/src/init.c +++ b/src/init.c @@ -812,7 +812,7 @@ extern void * __stack_chk_guard; DLLEXPORT int julia_trampoline(int argc, char **argv, int (*pmain)(int ac,char *av[]), char *build_path) { -#if defined(_OS_WINDOWS_) //&& !defined(_WIN64) +#if defined(_OS_WINDOWS_) SetUnhandledExceptionFilter(exception_handler); #endif unsigned char * p = (unsigned char *) &__stack_chk_guard; From 2d77ff871b0278bdecff34b5e5d40e570f2bedcc Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 19 Dec 2013 02:43:14 -0500 Subject: [PATCH 56/89] correct (reverse) byte order in UnwindData array --- src/debuginfo.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index 52b2eac0713bc..cc61889712221 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -24,14 +24,14 @@ class JuliaJITEventListener: public JITEventListener uint8_t *UnwindData = (uint8_t*)((((uintptr_t)&tbl[1])+3)&~(uintptr_t)3); RUNTIME_FUNCTION fn = {0,(DWORD)Size,(DWORD)(intptr_t)(UnwindData-(uint8_t*)Code)}; tbl[0] = fn; - UnwindData[0] = 0x20; // version info, UNW_FLAG_NHANDLER + UnwindData[0] = 0x01; // version info, UNW_FLAG_NHANDLER UnwindData[1] = 4; // size of prolog (bytes) UnwindData[2] = 2; // count of unwind codes (slots) - UnwindData[3] = 0x50; // frame register (rbp) = rsp - UnwindData[4] = 0x01; // first instruction - UnwindData[5] = 0x05; // push RBP - UnwindData[6] = 0x04; // second instruction - UnwindData[7] = 0x10; // mov RBP, RSP + UnwindData[3] = 0x05; // frame register (rbp) = rsp + UnwindData[4] = 4; // second instruction + UnwindData[5] = 0x01; // mov RBP, RSP + UnwindData[6] = 1; // first instruction + UnwindData[7] = 0x50; // push RBP RtlAddFunctionTable(tbl,1,(DWORD64)Code); #endif } From 2e10830ed5a97dec9df1eeebf7949d135a10089a Mon Sep 17 00:00:00 2001 From: "Blake R. Johnson" Date: Thu, 19 Dec 2013 09:23:31 -0500 Subject: [PATCH 57/89] Fix #5132. Disable use of AVX2 and BMI2 instructions in LLC. In some basic testing, it looks sufficient to disable AVX2 *or* BMI2 (not required to disable both). Since there are known bugs with these instructions in LLVM3.3, though, disabling both to be safe. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9dd4cfeb1179e..9f85f150929d3 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ $(BUILD)/etc/julia/juliarc.jl: etc/juliarc.jl | $(BUILD)/etc/julia $(BUILD)/$(JL_PRIVATE_LIBDIR)/sys%ji: $(BUILD)/$(JL_PRIVATE_LIBDIR)/sys%bc $(BUILD)/$(JL_PRIVATE_LIBDIR)/sys%o: $(BUILD)/$(JL_PRIVATE_LIBDIR)/sys%bc - $(call spawn,$(LLVM_LLC)) -filetype=obj -relocation-model=pic -o $@ $< + $(call spawn,$(LLVM_LLC)) -filetype=obj -relocation-model=pic -mattr=-bmi2,-avx2 -o $@ $< $(BUILD)/$(JL_PRIVATE_LIBDIR)/sys%$(SHLIB_EXT): $(BUILD)/$(JL_PRIVATE_LIBDIR)/sys%o $(CXX) -shared -fPIC -L$(BUILD)/$(JL_PRIVATE_LIBDIR) -L$(BUILD)/$(JL_LIBDIR) -o $@ $< \ From a4752517016ce3f1679276ce5b11613f47da79e1 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 19 Dec 2013 16:16:16 -0500 Subject: [PATCH 58/89] simplify inv(Complex128) --- base/complex.jl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/base/complex.jl b/base/complex.jl index d7b1b61c59df6..62c76882cb225 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -233,8 +233,18 @@ function inv(w::Complex128) s = 1.0 cd >= half*ov && (c=half*c; d=half*d; s=s*half) # scale down c,d cd <= un*two/ϵ && (c=c*bs; d=d*bs; s=s*bs ) # scale up c,d - abs(d)<=abs(c) ? ((p,q)=robust_cdiv1(1.0,0.0,c,d)) : - ((p,q)=robust_cdiv1(0.0,1.0,d,c); q=-q) + if abs(d)<=abs(c) + r = d/c + t = 1.0/(c+d*r) + p = t + q = -r * t + else + c, d = d, c + r = d/c + t = 1.0/(c+d*r) + p = r * t + q = -t + end return Complex128(p*s,q*s) # undo scaling end From bb6ab0a5ad7e60a0f1661e5f39cfac73df61e65d Mon Sep 17 00:00:00 2001 From: Tobias Knopp Date: Thu, 19 Dec 2013 20:57:16 +0100 Subject: [PATCH 59/89] Shorten julia.expmap --- src/julia.expmap | 386 +---------------------------------------------- 1 file changed, 5 insertions(+), 381 deletions(-) diff --git a/src/julia.expmap b/src/julia.expmap index 9724203ca2c9c..ace19cc2c500f 100644 --- a/src/julia.expmap +++ b/src/julia.expmap @@ -3,9 +3,7 @@ alloc_*w; allocobj; asprintf; - bitvector_any1; - bitvector_count; - bitvector_next; + bitvector_*; clock_now; ev_break; get_exename; @@ -13,369 +11,11 @@ int32hash; int64hash; int64to32hash; - ios_close; - ios_copy; - ios_copyall; - ios_copyuntil; - ios_eof; - ios_fd; - ios_file; - ios_flush; - ios_get_readable; - ios_get_writable; - ios_getc; - ios_getutf8; - ios_mem; - ios_peekc; - ios_peekutf8; - ios_pos; - ios_printf; - ios_purge; - ios_putc; - ios_pututf8; - ios_read; - ios_readall; - ios_readline; - ios_seek; - ios_seek_end; - ios_skip; - ios_splitbuf; - ios_stderr; - ios_stdin; - ios_stdout; - ios_takebuf; - ios_trunc; - ios_write; - ios_write_direct; + ios_*; iswprint; - jl_; - jl_alloc_array_1d; - jl_alloc_array_2d; - jl_alloc_array_3d; - jl_alloc_cell_1d; - jl_alloc_tuple; - jl_cell_1d_push; - jl_cell_1d_push2; - jl_checked_assignment; - jl_apply_generic; - jl_array_del_beg; - jl_array_del_end; - jl_array_grow_beg; - jl_array_grow_end; - jl_array_sizehint; - jl_array_ptr; - jl_arrayref; - jl_arrayset; - jl_arrayunset; - jl_array_to_string; - jl_ast_rettype; - jl_atexit_hook; - jl_backtrace_type; - jl_base_module; - jl_boundp; - jl_breakpoint; - jl_declare_constant; - jl_defines_or_exports_p; - jl_box_*; - jl_unbox_*; - jl_callback; - jl_clear_input; - jl_close_uv; - jl_forceclose_uv; - jl_compile_hint; - jl_compress_ast; - jl_connect_raw; - jl_continue_sym; - jl_core_module; - jl_cpu_cores; - jl_cstr_to_string; - jl_current_module; - jl_current_os; - jl_current_output_stream; - jl_current_output_stream_obj; - jl_current_task; - jl_cwd; - jl_defer_signal; - jl_dlsym; - jl_dlsym_e; - jl_dump_function; - jl_f_*; - jl_function_ptr; - jl_egal; - jl_enable_color; - jl_enable_inference; - jl_enq_send_req; - jl_enter_handler; - jl_environ; - jl_eqtable_get; - jl_eqtable_next; - jl_eqtable_put; - jl_eqtable_pop; - jl_errno; - jl_error; - jl_errorexception_type; - jl_exception_in_transit; - jl_exit; - jl_expand; - jl_expr_type; - jl_copy_ast; - jl_eval_string; - jl_exception_occurred; - jl_exception_clear; - jl_tuple; - jl_type_error_rt; - jl_typeof_str; - jl_typename_str; - jl_array_eltype; - jl_array_rank; - jl_array_size; - jl_get_field; - jl_call1; - jl_call2; - jl_sigatomic_begin; - jl_sigatomic_end; - jl_init; - jl_ascii_string_type; - jl_utf8_string_type; - jl_fd_clr; - jl_fd_isset; - jl_fd_set; - jl_fd_zero; - jl_field_offsets; - jl_flush_cstdio; - jl_free2; - jl_fstat; - jl_gc_add_finalizer; - jl_gc_collect; - jl_gc_disable; - jl_gc_enable; - jl_gc_is_enabled; - jl_gc_total_bytes; - jl_gc_lookfor; - jl_gc_new_weakref; - jl_gc_counted_malloc; - jl_gc_counted_free; - jl_gc_counted_realloc; - jl_gc_counted_realloc_with_old_size; - jl_gensym; - jl_get_binding; - jl_get_current_module; - jl_get_current_task; - jl_get_global; - jl_get_nth_field; - jl_get_root_symbol; - jl_get_system_hooks; - jl_get_uv_hooks; - jl_getaddrinfo; - jl_getpid; - jl_getutf8; - jl_global_event_loop; - jl_hrtime; - jl_idle_init; - jl_idle_start; - jl_idle_stop; - jl_init_frontend; - jl_init_pipe; - jl_install_sigint_handler; - jl_ios_buf_base; - jl_ios_eof; - jl_ios_fd; - jl_ios_size; - jl_is_const; - jl_is_debugbuild; - jl_is_leaf_type; - jl_is_rest_arg; - jl_is_unix; - jl_last_errno; - jl_lisp_prompt; - jl_listen; - jl_load_; - jl_load; - jl_load_and_lookup; - jl_load_dynamic_library; - jl_load_dynamic_library_e; - jl_load_file_string; - jl_loaderror_type; - jl_load_file_string; - jl_locate_sysimg; - jl_lseek; - jl_lstat; - jl_macroexpand; - jl_main_module; - jl_make_async; - jl_make_pipe; - jl_make_tcp; - jl_make_timer; - jl_matching_methods; - jl_match_method; - jl_method_def; - jl_mmap; - jl_module_export; - jl_module_names; - jl_module_name; - jl_module_parent; - jl_module_type; - jl_module_usings; - jl_native_alignment; - jl_next_from_addrinfo; - jl_new_box; - jl_is_char_signed; - jl_nb_available; - jl_new_array; - jl_new_closure; - jl_new_event_loop; - jl_new_gf_internal; - jl_new_lambda_info; - jl_new_struct_uninit; - jl_new_struct; - jl_new_structv; - jl_nothing; - jl_object_id; - jl_os_name; - jl_parse_input_line; - jl_parse_input_line; - jl_parse_string; - jl_pchar_to_array; - jl_pchar_to_string; - jl_pgcstack; - jl_prepare_ast; - jl_ast_rettype; - jl_print_int64; - jl_print_symbol; - jl_printf; - jl_process_events; - jl_process_exited; - jl_process_exit_status; - jl_process_signaled; - jl_process_stop_signal; - jl_process_stopped; - jl_process_stop_signal; - jl_process_term_signal; - jl_ptr_to_array; - jl_ptr_to_array_1d; - jl_putc; - jl_putc_copy; - jl_puts; - jl_pututf8; - jl_pututf8_copy; - jl_pwrite; - jl_read_buffer; - jl_readdir; - jl_readuntil; - jl_RTLD_DEFAULT_handle; - jl_throw; - jl_rethrow; - jl_rethrow_other; - jl_throw_with_superfluous_argument; - jl_get_backtrace; - jl_backtrace_from_here; - jl_lookup_code_address; - jl_read_sonames; + jl_*; rec_backtrace; - jl_profile_init; - jl_profile_get_data; - jl_profile_len_data; - jl_profile_maxlen_data; - jl_profile_clear_data; - jl_profile_start_timer; - jl_profile_stop_timer; - jl_profile_is_running; - jl_reshape_array; - jl_restore_system_image; - jl_run_event_loop; - jl_run_once; - jl_save_system_image; - jl_set_const; - jl_set_current_module; - jl_set_current_output_stream_obj; - jl_set_global; - jl_set_timeval; - jl_setjmp; - jl_show; - jl_show_any; - jl_signal_pending; - jl_sizeof_*; - jl_sockaddr_from_addrinfo; - jl_sockaddr_set_port; - jl_sockaddr_in_is_ip4; - jl_sockaddr_in_is_ip6; - jl_sockaddr_is_ip4; - jl_sockaddr_is_ip6; - jl_sockaddr_host4; - jl_sockaddr_host6; - jl_tcp4_connect; - jl_tcp6_connect; - jl_spawn; - jl_stackovf_exception; - jl_start_io_thread; - jl_start_reading; - jl_stat; - jl_stat_blksize; - jl_stat_blocks; - jl_stat_ctime; - jl_stat_dev; - jl_stat_gid; - jl_stat_ino; - jl_stat_mode; - jl_stat_mtime; - jl_stat_nlink; - jl_stat_rdev; - jl_stat_size; - jl_stat_uid; - jl_static_show; - jl_stderr_obj; - jl_stderr_stream; - jl_stdin_callback; - jl_stdin_callback; - jl_stdin_stream; - jl_stdout_obj; - jl_stdout_stream; - jl_strtod; - jl_strtof; - jl_substrtod; - jl_substrtof; - jl_symbol; - jl_symbol_lookup; - jl_symbol_n; - jl_symbol_name; - jl_tagged_gensym; - jl_takebuf_array; - jl_takebuf_raw; - jl_takebuf_string; - jl_tcp_bind; - jl_tcp_bind6; - jl_tcp_init; - jl_test; - jl_poll_start; - jl_pop_handler; - jl_fs_poll_start; - jl_fs_event_init; - jl_fs_unlink; - jl_fs_rename; - jl_fs_sendfile; - jl_fs_write; - jl_fs_write_byte; - jl_fs_read; - jl_fs_read_byte; - jl_fs_close; - jl_toplevel_eval; - jl_type_intersection; - jl_type_match; - jl_types_equal; - jl_typeassert; - jl_array_len_; - jl_uncompress_ast; - jl_uv_*; - jl_wrap_raw_dl_handle; - jl_write; - jl_write_no_copy; - jl_value_ptr; - jl_value_to_pointer; - jl_zero_subnormals; - julia_free; - julia_home; - julia_init; - julia_trampoline; + julia_*; libsupport_init; locale_is_utf8; localtime_r; @@ -385,31 +25,15 @@ memhash_seed; open_any_tcp_port; repl_callback_enable; - jl_init_repl; restore_arg_area_loc; restore_signals; rl_clear_input; save_arg_area_loc; - jl_SC_CLK_TCK; - jl_getpagesize; - u8_isvalid; - u8_strlen; - u8_strwidth; - u8_reverse; + u8_*; wcwidth; uv_*; add_library_mapping; - jl_stackovf_exception; - jl_memory_exception; - jl_diverror_exception; - jl_domain_exception; - jl_overflow_exception; - jl_inexact_exception; - jl_undefref_exception; - jl_interrupt_exception; - jl_bounds_exception; - /* freebsd */ environ; __progname; From d7d671d1eb1814666b2048c202f9b574df6acff7 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 19 Dec 2013 21:48:28 -0500 Subject: [PATCH 60/89] use Any for default inner constructor argument types. closes #4026 --- src/julia-syntax.scm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 5f73beb8dfcab..70d19a2f8df7a 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -654,8 +654,7 @@ (define (default-inner-ctor name field-names field-types) (let ((field-names (safe-field-names field-names field-types))) - `(function (call ,name - ,@(map make-decl field-names field-types)) + `(function (call ,name ,@field-names) (block (call new ,@field-names))))) From 0d4b612dfb341c9aaef725b46ed640fa1c6ab68a Mon Sep 17 00:00:00 2001 From: amitmurthy Date: Fri, 20 Dec 2013 10:25:28 +0530 Subject: [PATCH 61/89] Fix state restoration in reload --- base/loading.jl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index 51ff2236451a2..e765b5cbe0417 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -55,8 +55,11 @@ function _require(path) else last = toplevel_load toplevel_load = false - reload_path(path) - toplevel_load = last + try + reload_path(path) + finally + toplevel_load = last + end end end @@ -70,8 +73,11 @@ function reload(name::String) end last = toplevel_load toplevel_load = false - reload_path(path) - toplevel_load = last + try + reload_path(path) + finally + toplevel_load = last + end if refs !== nothing for r in refs; wait(r); end end From 75b43c0e362f770d977f9c3e83f3ada807a10f53 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 20 Dec 2013 02:06:38 -0500 Subject: [PATCH 62/89] WIN64: usually catch FPE and SEGV errors --- src/codegen.cpp | 2 +- src/debuginfo.cpp | 23 ++++++++++++++++------- src/init.c | 19 ++++++++++++++++++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index b41dc9eb0ddf7..c8ba0ac326624 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3832,7 +3832,7 @@ extern "C" void jl_init_codegen(void) std::vector attrvec (mattr, mattr+2); jl_ExecutionEngine = EngineBuilder(jl_Module) .setEngineKind(EngineKind::JIT) -#if defined(_OS_WINDOWS_) +#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) .setJITMemoryManager(new JITMemoryManagerWin()) #endif .setTargetOptions(options) diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index cc61889712221..1a1557c55d35d 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -6,6 +6,8 @@ struct FuncInfo{ std::vector lines; }; +extern "C" EXCEPTION_DISPOSITION _seh_exception_handler(PEXCEPTION_RECORD ExceptionRecord,void *EstablisherFrame, PCONTEXT ContextRecord, void *DispatcherContext); + class JuliaJITEventListener: public JITEventListener { std::map info; @@ -19,12 +21,18 @@ class JuliaJITEventListener: public JITEventListener { FuncInfo tmp = {&F, Size, Details.LineStarts}; info[(size_t)(Code)] = tmp; -#if defined(_OS_WINDOWS_) - PRUNTIME_FUNCTION tbl = (PRUNTIME_FUNCTION)(((uintptr_t)Code + Size + 3)&~(uintptr_t)3); +#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) + uintptr_t catchjmp = (uintptr_t)Code+Size; + *(uint8_t*)(catchjmp+0) = 0x48; + *(uint8_t*)(catchjmp+1) = 0xb8; // mov RAX, QWORD PTR [...] + *(uint64_t*)(catchjmp+2) = (uint64_t)&_seh_exception_handler; + *(uint8_t*)(catchjmp+10) = 0xff; + *(uint8_t*)(catchjmp+11) = 0xe0; // jmp RAX + PRUNTIME_FUNCTION tbl = (PRUNTIME_FUNCTION)((catchjmp+12+3)&~(uintptr_t)3); uint8_t *UnwindData = (uint8_t*)((((uintptr_t)&tbl[1])+3)&~(uintptr_t)3); - RUNTIME_FUNCTION fn = {0,(DWORD)Size,(DWORD)(intptr_t)(UnwindData-(uint8_t*)Code)}; + RUNTIME_FUNCTION fn = {0,(DWORD)Size+13,(DWORD)(intptr_t)(UnwindData-(uint8_t*)Code)}; tbl[0] = fn; - UnwindData[0] = 0x01; // version info, UNW_FLAG_NHANDLER + UnwindData[0] = 0x09; // version info, UNW_FLAG_EHANDLER UnwindData[1] = 4; // size of prolog (bytes) UnwindData[2] = 2; // count of unwind codes (slots) UnwindData[3] = 0x05; // frame register (rbp) = rsp @@ -32,6 +40,7 @@ class JuliaJITEventListener: public JITEventListener UnwindData[5] = 0x01; // mov RBP, RSP UnwindData[6] = 1; // first instruction UnwindData[7] = 0x50; // push RBP + *(DWORD*)&UnwindData[8] = (DWORD)(catchjmp-(intptr_t)Code); RtlAddFunctionTable(tbl,1,(DWORD64)Code); #endif } @@ -99,7 +108,7 @@ void getFunctionInfo(const char **name, int *line, const char **filename, size_t } } -#if defined(_OS_WINDOWS_) +#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) class JITMemoryManagerWin : public JITMemoryManager { private: JITMemoryManager *JMM; @@ -113,11 +122,11 @@ class JITMemoryManagerWin : public JITMemoryManager { virtual void AllocateGOT() { JMM->AllocateGOT(); HasGOT = true; } virtual uint8_t *getGOTBase() const { return JMM->getGOTBase(); } virtual uint8_t *startFunctionBody(const Function *F, - uintptr_t &ActualSize) { ActualSize += 16; uint8_t *ret = JMM->startFunctionBody(F,ActualSize); ActualSize -= 16; return ret; } + uintptr_t &ActualSize) { ActualSize += 48; uint8_t *ret = JMM->startFunctionBody(F,ActualSize); ActualSize -= 48; return ret; } virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize, unsigned Alignment) { return JMM->allocateStub(F,StubSize,Alignment); } virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart, - uint8_t *FunctionEnd) { return JMM->endFunctionBody(F,FunctionStart,FunctionEnd+16); } + uint8_t *FunctionEnd) { return JMM->endFunctionBody(F,FunctionStart,FunctionEnd+48); } virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) { return JMM->allocateSpace(Size,Alignment); } virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) { return JMM->allocateGlobal(Size,Alignment); } virtual void deallocateFunctionBody(void *Body) { return JMM->deallocateFunctionBody(Body); } diff --git a/src/init.c b/src/init.c index 7d8f3a2ee20ee..2b8f3cb6116ba 100644 --- a/src/init.c +++ b/src/init.c @@ -215,14 +215,20 @@ static BOOL WINAPI sigint_handler(DWORD wsig) //This needs winapi types to guara } return 1; } -static LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) +static LONG WINAPI _exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo, int in_ctx) { if (ExceptionInfo->ExceptionRecord->ExceptionFlags == 0) { switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_INT_DIVIDE_BY_ZERO: + fpreset(); + if (!in_ctx) + jl_throw(jl_diverror_exception); jl_throw_in_ctx(jl_diverror_exception, ExceptionInfo->ContextRecord, 0); return EXCEPTION_CONTINUE_EXECUTION; case EXCEPTION_STACK_OVERFLOW: + bt_size = 0; + if (!in_ctx) + jl_rethrow_other(jl_stackovf_exception); jl_throw_in_ctx(jl_stackovf_exception, ExceptionInfo->ContextRecord, 0); return EXCEPTION_CONTINUE_EXECUTION; } @@ -278,6 +284,17 @@ static LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) } return EXCEPTION_CONTINUE_SEARCH; } +static LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) { + return _exception_handler(ExceptionInfo,1); +} +#if defined(_CPU_X86_64_) +EXCEPTION_DISPOSITION _seh_exception_handler(PEXCEPTION_RECORD ExceptionRecord, void *EstablisherFrame, PCONTEXT ContextRecord, void *DispatcherContext) { + EXCEPTION_POINTERS ExceptionInfo; + ExceptionInfo.ExceptionRecord = ExceptionRecord; + ExceptionInfo.ContextRecord = ContextRecord; + return _exception_handler(&ExceptionInfo,0); +} +#endif #else void restore_signals() { From 1c60f94d7602ceb4a725e54f2f4f8e12e1e93da0 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 19 Dec 2013 23:45:02 -0800 Subject: [PATCH 63/89] Need to wrap these lines in windows-only #ifdefs --- src/debuginfo.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index 1a1557c55d35d..8728a5681f9f6 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -6,7 +6,9 @@ struct FuncInfo{ std::vector lines; }; +#ifdef _OS_WINDOWS_ extern "C" EXCEPTION_DISPOSITION _seh_exception_handler(PEXCEPTION_RECORD ExceptionRecord,void *EstablisherFrame, PCONTEXT ContextRecord, void *DispatcherContext); +#endif class JuliaJITEventListener: public JITEventListener { From 996176238fc4ec68e23c7d4813bd0b89eafb64c1 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 20 Dec 2013 03:48:22 -0500 Subject: [PATCH 64/89] some formatting fixes --- src/init.c | 115 ++++++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 54 deletions(-) diff --git a/src/init.c b/src/init.c index 797ea6623315e..2f8952dffe8c0 100644 --- a/src/init.c +++ b/src/init.c @@ -80,18 +80,9 @@ static void jl_find_stack_bottom(void) } #ifdef _OS_WINDOWS_ -void __cdecl fpe_handler(int arg,int num) -#else -void fpe_handler(int arg) -#endif +void __cdecl fpe_handler(int arg, int num) { (void)arg; -#ifndef _OS_WINDOWS_ - sigset_t sset; - sigemptyset(&sset); - sigaddset(&sset, SIGFPE); - sigprocmask(SIG_UNBLOCK, &sset, NULL); -#else fpreset(); signal(SIGFPE, (void (__cdecl *)(int))fpe_handler); switch(num) { @@ -102,11 +93,31 @@ void fpe_handler(int arg) jl_errorf("Unexpected FPE Error 0x%X", num); break; case _FPE_ZERODIVIDE: -#endif jl_throw(jl_diverror_exception); -#ifdef _OS_WINDOWS_ break; } +} +#else +void fpe_handler(int arg) +{ + (void)arg; + sigset_t sset; + sigemptyset(&sset); + sigaddset(&sset, SIGFPE); + sigprocmask(SIG_UNBLOCK, &sset, NULL); + + jl_throw(jl_diverror_exception); +} +#endif + +static int is_addr_on_stack(void *addr) +{ +#ifdef COPY_STACKS + return ((char*)addr > (char*)jl_stack_lo-3000000 && + (char*)addr < (char*)jl_stack_hi); +#else + return ((char*)addr > (char*)jl_current_task->stack-8192 && + (char*)addr < (char*)jl_current_task->stack+jl_current_task->ssize); #endif } @@ -116,16 +127,7 @@ void segv_handler(int sig, siginfo_t *info, void *context) { sigset_t sset; - if ( in_jl_ || ( -#ifdef COPY_STACKS - (char*)info->si_addr > (char*)jl_stack_lo-3000000 && - (char*)info->si_addr < (char*)jl_stack_hi -#else - (char*)info->si_addr > (char*)jl_current_task->stack-8192 && - (char*)info->si_addr < - (char*)jl_current_task->stack+jl_current_task->ssize -#endif - )) { + if (in_jl_ || is_addr_on_stack(info->si_addr)) { sigemptyset(&sset); sigaddset(&sset, SIGSEGV); sigprocmask(SIG_UNBLOCK, &sset, NULL); @@ -150,9 +152,10 @@ volatile sig_atomic_t jl_defer_signal = 0; #ifdef _OS_WINDOWS_ void restore_signals() { - SetConsoleCtrlHandler(NULL,0); //turn on ctrl-c handler + SetConsoleCtrlHandler(NULL, 0); //turn on ctrl-c handler } -void jl_throw_in_ctx(jl_value_t* excpt, CONTEXT *ctxThread, int bt) + +void jl_throw_in_ctx(jl_value_t *excpt, CONTEXT *ctxThread, int bt) { assert(excpt != NULL); bt_size = bt ? rec_backtrace_ctx(bt_data, MAX_BT_SIZE, ctxThread) : 0; @@ -169,9 +172,11 @@ void jl_throw_in_ctx(jl_value_t* excpt, CONTEXT *ctxThread, int bt) #error WIN16 not supported :P #endif } + volatile HANDLE hMainThread = NULL; DLLEXPORT void jlbacktrace(); DLLEXPORT void gdblookup(ptrint_t ip); + static BOOL WINAPI sigint_handler(DWORD wsig) //This needs winapi types to guarantee __stdcall { int sig; @@ -215,6 +220,7 @@ static BOOL WINAPI sigint_handler(DWORD wsig) //This needs winapi types to guara } return 1; } + static LONG WINAPI _exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo, int in_ctx) { if (ExceptionInfo->ExceptionRecord->ExceptionFlags == 0) { @@ -284,24 +290,31 @@ static LONG WINAPI _exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo, } return EXCEPTION_CONTINUE_SEARCH; } -static LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) { + +static LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) +{ return _exception_handler(ExceptionInfo,1); } + #if defined(_CPU_X86_64_) -EXCEPTION_DISPOSITION _seh_exception_handler(PEXCEPTION_RECORD ExceptionRecord, void *EstablisherFrame, PCONTEXT ContextRecord, void *DispatcherContext) { +EXCEPTION_DISPOSITION _seh_exception_handler(PEXCEPTION_RECORD ExceptionRecord, void *EstablisherFrame, PCONTEXT ContextRecord, void *DispatcherContext) +{ EXCEPTION_POINTERS ExceptionInfo; ExceptionInfo.ExceptionRecord = ExceptionRecord; ExceptionInfo.ContextRecord = ContextRecord; return _exception_handler(&ExceptionInfo,0); } #endif -#else + +#else // #ifdef _OS_WINDOWS_ + void restore_signals() { sigset_t sset; sigemptyset(&sset); sigprocmask(SIG_SETMASK, &sset, 0); } + void sigint_handler(int sig, siginfo_t *info, void *context) { if (jl_defer_signal) { @@ -330,11 +343,13 @@ static void jl_uv_exitcleanup_add(uv_handle_t* handle, struct uv_shutdown_queue if (!queue->first) queue->first = item; queue->last = item; } + static void jl_uv_exitcleanup_walk(uv_handle_t* handle, void *arg) { if (handle != (uv_handle_t*)jl_uv_stdout && handle != (uv_handle_t*)jl_uv_stderr) jl_uv_exitcleanup_add(handle, arg); } + DLLEXPORT void uv_atexit_hook() { #if defined(JL_GC_MARKSWEEP) && defined(GC_FINAL_STATS) @@ -527,9 +542,9 @@ static mach_port_t segv_port = 0; extern boolean_t exc_server(mach_msg_header_t *, mach_msg_header_t *); -void * mach_segv_listener(void *arg) +void *mach_segv_listener(void *arg) { - (void) arg; + (void)arg; while (1) { int ret = mach_msg_server(exc_server,2048,segv_port,MACH_MSG_TIMEOUT_NONE); printf("mach_msg_server: %s\n", mach_error_string(ret)); @@ -553,13 +568,13 @@ extern volatile mach_port_t mach_profiler_thread; #endif //exc_server uses dlsym to find symbol -DLLEXPORT kern_return_t catch_exception_raise - (mach_port_t exception_port, - mach_port_t thread, - mach_port_t task, - exception_type_t exception, - exception_data_t code, - mach_msg_type_number_t code_count) +DLLEXPORT +kern_return_t catch_exception_raise(mach_port_t exception_port, + mach_port_t thread, + mach_port_t task, + exception_type_t exception, + exception_data_t code, + mach_msg_type_number_t code_count) { unsigned int count = MACHINE_THREAD_STATE_COUNT; unsigned int exc_count = X86_EXCEPTION_STATE64_COUNT; @@ -576,16 +591,7 @@ DLLEXPORT kern_return_t catch_exception_raise ret = thread_get_state(thread,x86_EXCEPTION_STATE64,(thread_state_t)&exc_state,&exc_count); HANDLE_MACH_ERROR("thread_get_state(1)",ret); uint64_t fault_addr = exc_state.__faultvaddr; - if ( -#ifdef COPY_STACKS - (char*)fault_addr > (char*)jl_stack_lo-3000000 && - (char*)fault_addr < (char*)jl_stack_hi -#else - (char*)fault_addr > (char*)jl_current_task->stack-8192 && - (char*)fault_addr < - (char*)jl_current_task->stack+jl_current_task->ssize -#endif - ) { + if (is_addr_on_stack(fault_addr)) { ret = thread_get_state(thread,x86_THREAD_STATE64,(thread_state_t)&state,&count); HANDLE_MACH_ERROR("thread_get_state(2)",ret); old_state = state; @@ -633,14 +639,14 @@ void julia_init(char *imageFile, int build_mode) jl_RTLD_DEFAULT_handle->handle = jl_dl_handle->handle; #endif #ifdef _OS_WINDOWS_ - uv_dlopen("ntdll.dll",jl_ntdll_handle); //bypass julia's pathchecking for system dlls - uv_dlopen("kernel32.dll",jl_kernel32_handle); - uv_dlopen("msvcrt.dll",jl_crtdll_handle); - uv_dlopen("ws2_32.dll",jl_winsock_handle); + uv_dlopen("ntdll.dll", jl_ntdll_handle); // bypass julia's pathchecking for system dlls + uv_dlopen("kernel32.dll", jl_kernel32_handle); + uv_dlopen("msvcrt.dll", jl_crtdll_handle); + uv_dlopen("ws2_32.dll", jl_winsock_handle); _jl_exe_handle.handle = GetModuleHandleA(NULL); - if (!DuplicateHandle( GetCurrentProcess(), GetCurrentThread(), - GetCurrentProcess(), (PHANDLE)&hMainThread, 0, - TRUE, DUPLICATE_SAME_ACCESS )) { + if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), + GetCurrentProcess(), (PHANDLE)&hMainThread, 0, + TRUE, DUPLICATE_SAME_ACCESS)) { JL_PRINTF(JL_STDERR, "Couldn't access handle to main thread\n"); } SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES); @@ -648,7 +654,8 @@ void julia_init(char *imageFile, int build_mode) needsSymRefreshModuleList = 0; uv_lib_t jl_dbghelp; uv_dlopen("dbghelp.dll",&jl_dbghelp); - if (uv_dlsym(&jl_dbghelp,"SymRefreshModuleList",(void**)&hSymRefreshModuleList)) hSymRefreshModuleList = 0; + if (uv_dlsym(&jl_dbghelp, "SymRefreshModuleList", (void**)&hSymRefreshModuleList)) + hSymRefreshModuleList = 0; #endif jl_io_loop = uv_default_loop(); //this loop will internal events (spawining process etc.) init_stdio(); From d83dad3caab3f065f6b7b53125cf926b2e88eebc Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Fri, 20 Dec 2013 09:24:43 -0500 Subject: [PATCH 65/89] Adds information on operator precedence Adds a order of operations table and a note for Matlab users. --- doc/manual/mathematical-operations.rst | 21 +++++++++++++++++++++ doc/manual/noteworthy-differences.rst | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/doc/manual/mathematical-operations.rst b/doc/manual/mathematical-operations.rst index 58981f5885ec1..c9d79670190a2 100644 --- a/doc/manual/mathematical-operations.rst +++ b/doc/manual/mathematical-operations.rst @@ -293,6 +293,27 @@ expressions with side effects (such as printing) in chained comparisons. If side effects are required, the short-circuit ``&&`` operator should be used explicitly (see :ref:`man-short-circuit-evaluation`). +Operator Precedence +~~~~~~~~~~~~~~~~~~~ + +Julia applies the following order of operations, from highest precedence +to lowest: + +================= ============================================================================================= +Category Operators +================= ============================================================================================= +Syntax ``.`` followed by ``::`` +Exponentiation ``^`` and its elementwise equivalent ``.^`` +Fractions ``//`` and ``.//`` +Multiplication ``* / % & \`` and ``.* ./ .% .\`` +Bitshifts ``<< >> >>>`` and ``.<< .>> .>>>`` +Addition ``+ - | $`` and ``.+ .-`` +Syntax ``: ..`` followed by ``|>`` +Comparisons ``> < >= <= == === != !== <:`` and ``.> .< .>= .<= .== .!=`` +Control flow ``&&`` followed by ``||`` followed by ``?`` +Assignments ``= += -= *= /= //= \= ^= %= |= &= $= <<= >>= >>>=`` and ``.+= .-= .*= ./= .//= .\= .^= .%=`` +================= ============================================================================================= + .. _man-elementary-functions: Elementary Functions diff --git a/doc/manual/noteworthy-differences.rst b/doc/manual/noteworthy-differences.rst index 599e282c756dc..a1bf39badd76b 100644 --- a/doc/manual/noteworthy-differences.rst +++ b/doc/manual/noteworthy-differences.rst @@ -52,6 +52,12 @@ differences that may trip up Julia users accustomed to MATLAB: - If ``A`` and ``B`` are arrays, ``A == B`` doesn't return an array of booleans. Use ``A .== B`` instead. Likewise for the other boolean operators, ``<``, ``>``, ``!=``, etc. +- The operators ``&``, ``|``, and ``$`` perform the bitwise operations and, + or, and xor, respectively, and have precedence similar to Python's bitwise + operators (not like C). They can operate on scalars or elementwise + across arrays and can be used to combine logical arrays, but note the + difference in order of operations—parentheses may be required (e.g., + to select elements of ``A`` equal to 1 or 2 use ``(A .== 1) | (A .== 2)``). - The elements of a collection can be passed as arguments to a function using ``...``, as in ``xs=[1,2]; f(xs...)``. - Julia's ``svd`` returns singular values as a vector instead of as a From 536034362b7f2f5aabe82e9bd9bd3e9369dc57c6 Mon Sep 17 00:00:00 2001 From: Brendan O'Connor Date: Fri, 20 Dec 2013 11:42:15 -0500 Subject: [PATCH 66/89] Add macro definitions to ctags --- contrib/ctags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/ctags b/contrib/ctags index 5e119f1dfbae8..ca54ff7d65a78 100644 --- a/contrib/ctags +++ b/contrib/ctags @@ -1,4 +1,4 @@ --langdef=julia --langmap=julia:.jl ---regex-julia=/^[ \t]*function[ \t]+([^ \t({[]+).*$/\1/f,function/ +--regex-julia='/^[ \t]*(function|macro)[ \t]+([^ \t({[]+).*$/\2/f,function/' --regex-julia=/^[ \t]*(([^@#$ \t({[]+)|\(([^@#$ \t({[]+)\)|\((\$)\))[ \t]*(\{.*\})?[ \t]*\([^#]*\)[ \t]*=([^=].*$|$)/\2\3\4/f,function/ From 844bbec0118d3a556e6cc3a7bba7a3331200ad44 Mon Sep 17 00:00:00 2001 From: timholy Date: Fri, 20 Dec 2013 10:44:11 -0600 Subject: [PATCH 67/89] Add A_mul_B!(output, A, b) etc for sparse A --- base/linalg/sparse.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/base/linalg/sparse.jl b/base/linalg/sparse.jl index 945dfa6ca421f..e7c1d3baa89e8 100644 --- a/base/linalg/sparse.jl +++ b/base/linalg/sparse.jl @@ -24,6 +24,8 @@ function A_mul_B!(α::Number, A::SparseMatrixCSC, x::AbstractVector, β::Number, end y end +A_mul_B!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractVector) = A_mul_B!(one(eltype(x)), A, x, zero(eltype(y)), y) + function *{TA,S,Tx}(A::SparseMatrixCSC{TA,S}, x::AbstractVector{Tx}) T = promote_type(TA,Tx) A_mul_B!(one(T), A, x, zero(T), zeros(T, A.m)) @@ -46,6 +48,7 @@ function Ac_mul_B!(α::Number, A::SparseMatrixCSC, x::AbstractVector, β::Number end y end +Ac_mul_B!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractVector) = Ac_mul_B!(one(eltype(x)), A, x, zero(eltype(y)), y) function At_mul_B!(α::Number, A::SparseMatrixCSC, x::AbstractVector, β::Number, y::AbstractVector) A.n == length(y) || throw(DimensionMismatch("")) A.m == length(x) || throw(DimensionMismatch("")) @@ -63,6 +66,7 @@ function At_mul_B!(α::Number, A::SparseMatrixCSC, x::AbstractVector, β::Number end y end +At_mul_B!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractVector) = At_mul_B!(one(eltype(x)), A, x, zero(eltype(y)), y) function Ac_mul_B{TA,S,Tx}(A::SparseMatrixCSC{TA,S}, x::AbstractVector{Tx}) T = promote_type(TA, Tx) Ac_mul_B!(one(T), A, x, zero(T), zeros(T, A.n)) From b37deb6af6d067375706d28bf3fed022a14f1430 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 20 Dec 2013 12:36:48 -0500 Subject: [PATCH 68/89] remove newly-circular Vec2 constructor. fixes #5201 --- base/graphics.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/base/graphics.jl b/base/graphics.jl index e44f16cf61ff0..a378abdf3e370 100644 --- a/base/graphics.jl +++ b/base/graphics.jl @@ -55,8 +55,6 @@ immutable Vec2 y::Float64 end -Vec2(x::Real, y::Real) = Vec2(float64(x), float64(y)) - typealias Point Vec2 (+)(a::Vec2, b::Vec2) = Vec2(a.x + b.x, a.y + b.y) From 1c010e23aa052960dd7a0810310cc0126f8ac00e Mon Sep 17 00:00:00 2001 From: Michael Hatherly Date: Sat, 21 Dec 2013 18:00:36 +0200 Subject: [PATCH 69/89] Fixes #5203. Check whether `dir` is empty before trying `git add --all`. This is needed for git 1.8.5. --- base/pkg/git.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/base/pkg/git.jl b/base/pkg/git.jl index 81128c43d2381..cd33a67879a68 100644 --- a/base/pkg/git.jl +++ b/base/pkg/git.jl @@ -58,8 +58,10 @@ function snapshot(; dir="") head = readchomp(`rev-parse HEAD`, dir=dir) index = readchomp(`write-tree`, dir=dir) work = try - run(`add --all`, dir=dir) - run(`add .`, dir=dir) + if length(readdir(abspath(dir))) > 1 + run(`add --all`, dir=dir) + run(`add .`, dir=dir) + end readchomp(`write-tree`, dir=dir) finally run(`read-tree $index`, dir=dir) # restore index From f5a27e7237152b7dd2eec3720076550c5f101b7a Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Sat, 21 Dec 2013 16:05:36 -0500 Subject: [PATCH 70/89] test/git*.jl: don't use `echo` to read-and-write from processes. This is one of those areas where our current process I/O stuff is very awkward. Making write_and_readchomp an available function is not a good solution either. The whole thing needs some design work. --- test/gitutils.jl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/gitutils.jl b/test/gitutils.jl index 780256929fc24..422f8f80f67d4 100644 --- a/test/gitutils.jl +++ b/test/gitutils.jl @@ -1,8 +1,16 @@ +function write_and_readchomp(data, cmd::Cmd) + r, w, p = readandwrite(cmd) + print(w,data); close(w) + v = readchomp(r) + wait(p) + return v +end + function mktree(d::Dict) lstree = "" for (name, data) in d if isa(data, String) - sha1 = readchomp(`echo -n $data` |> `git hash-object -w --stdin`) + sha1 = write_and_readchomp(data, `git hash-object -w --stdin`) lstree *= "100644 blob $sha1\t$name\n" elseif isa(data, Dict) sha1 = mktree(data) @@ -13,7 +21,7 @@ function mktree(d::Dict) error("mktree: don't know what to do with $name => $data") end end - readchomp(`echo -n $lstree` |> `git mktree`) + write_and_readchomp(lstree, `git mktree`) end function verify_tree(d::Dict, tree::String) @@ -91,7 +99,7 @@ function git_setup(h::Dict, i::Dict, w::Dict, parents::String...) for parent in parents commit_tree = `$commit_tree -p $parent` end - head = readchomp(`echo $headt` |> commit_tree) + head = write_and_readchomp(headt, commit_tree) run(`git reset -q --soft $head`) run(`git read-tree $work`) # read work into the index From 3b8c4723581cdb33aabff2501e4a1df9925fb670 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Sat, 21 Dec 2013 16:05:36 -0500 Subject: [PATCH 71/89] test/git*.jl: don't use `echo` to read-and-write from processes. This is one of those areas where our current process I/O stuff is very awkward. Making write_and_readchomp an available function is not a good solution either. The whole thing needs some design work. --- test/gitutils.jl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/gitutils.jl b/test/gitutils.jl index 780256929fc24..422f8f80f67d4 100644 --- a/test/gitutils.jl +++ b/test/gitutils.jl @@ -1,8 +1,16 @@ +function write_and_readchomp(data, cmd::Cmd) + r, w, p = readandwrite(cmd) + print(w,data); close(w) + v = readchomp(r) + wait(p) + return v +end + function mktree(d::Dict) lstree = "" for (name, data) in d if isa(data, String) - sha1 = readchomp(`echo -n $data` |> `git hash-object -w --stdin`) + sha1 = write_and_readchomp(data, `git hash-object -w --stdin`) lstree *= "100644 blob $sha1\t$name\n" elseif isa(data, Dict) sha1 = mktree(data) @@ -13,7 +21,7 @@ function mktree(d::Dict) error("mktree: don't know what to do with $name => $data") end end - readchomp(`echo -n $lstree` |> `git mktree`) + write_and_readchomp(lstree, `git mktree`) end function verify_tree(d::Dict, tree::String) @@ -91,7 +99,7 @@ function git_setup(h::Dict, i::Dict, w::Dict, parents::String...) for parent in parents commit_tree = `$commit_tree -p $parent` end - head = readchomp(`echo $headt` |> commit_tree) + head = write_and_readchomp(headt, commit_tree) run(`git reset -q --soft $head`) run(`git read-tree $work`) # read work into the index From c86610952137ff1eeef605743c92a5a5abe1b340 Mon Sep 17 00:00:00 2001 From: Andreas Noack Jensen Date: Thu, 19 Dec 2013 09:48:09 +0100 Subject: [PATCH 72/89] Some error message cleanup to fix segfault when transposing sparse vector with illegal values. --- base/array.jl | 10 +++++----- base/base.jl | 4 ++++ base/exports.jl | 1 + base/linalg/exceptions.jl | 7 +------ base/sparse/sparsematrix.jl | 38 +++++++++++++++++++------------------ test/sparse.jl | 3 +++ 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/base/array.jl b/base/array.jl index 54e1baab9c37b..75824fe94f994 100644 --- a/base/array.jl +++ b/base/array.jl @@ -121,7 +121,7 @@ function reinterpret{T,S,N}(::Type{T}, a::Array{S}, dims::NTuple{N,Int}) end nel = div(length(a)*sizeof(S),sizeof(T)) if prod(dims) != nel - error("new dimensions $(dims) must be consistent with array size $(nel)") + throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $(nel)")) end ccall(:jl_reshape_array, Array{T,N}, (Any, Any, Any), Array{T,N}, a, dims) end @@ -129,7 +129,7 @@ reinterpret(t::Type,x) = reinterpret(t,[x])[1] function reshape{T,N}(a::Array{T}, dims::NTuple{N,Int}) if prod(dims) != length(a) - error("new dimensions $(dims) must be consistent with array size $(length(a))") + throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $(length(a))")) end ccall(:jl_reshape_array, Array{T,N}, (Any, Any, Any), Array{T,N}, a, dims) end @@ -598,12 +598,12 @@ function setindex!(A::Array, x, I::Union(Real,AbstractArray)...) nel *= length(idx) end if length(X) != nel - error("argument dimensions must match") + throw(DimensionMismatch("")) end if ndims(X) > 1 for i = 1:length(I) if size(X,i) != length(I[i]) - error("argument dimensions must match") + throw(DimensionMismatch("")) end end end @@ -996,7 +996,7 @@ end ## promotion to complex ## function complex{S<:Real,T<:Real}(A::Array{S}, B::Array{T}) - if size(A) != size(B); error("argument dimensions must match"); end + if size(A) != size(B); throw(DimensionMismatch("")); end F = similar(A, typeof(complex(zero(S),zero(T)))) for i=1:length(A) @inbounds F[i] = complex(A[i], B[i]) diff --git a/base/base.jl b/base/base.jl index e452e7cc8ac72..f09a934d59ea6 100644 --- a/base/base.jl +++ b/base/base.jl @@ -70,6 +70,10 @@ end type EOFError <: Exception end +type DimensionMismatch <: Exception + name::ASCIIString +end + type WeakRef value WeakRef() = WeakRef(nothing) diff --git a/base/exports.jl b/base/exports.jl index 65c1b4a71e01b..b1210c0c98f7f 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -138,6 +138,7 @@ export # Exceptions ArgumentError, + DimensionMismatch, EOFError, ErrorException, KeyError, diff --git a/base/linalg/exceptions.jl b/base/linalg/exceptions.jl index 8f96f82906337..b22872607fe4c 100644 --- a/base/linalg/exceptions.jl +++ b/base/linalg/exceptions.jl @@ -2,8 +2,7 @@ export LAPACKException, ARPACKException, SingularException, PosDefException, - RankDeficientException, - DimensionMismatch + RankDeficientException type LAPACKException <: Exception info::BlasInt @@ -24,7 +23,3 @@ end type RankDeficientException <: Exception info::BlasInt end - -type DimensionMismatch <: Exception - name::ASCIIString -end diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index b1453efaa2761..7ec26613e797e 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -2,6 +2,7 @@ # Assumes that no zeros are stored in the data structure # Assumes that row values in rowval for each colum are sorted # issorted(rowval[colptr[i]]:rowval[colptr[i+1]]-1) == true + type SparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti} m::Int # Number of rows n::Int # Number of columns @@ -37,7 +38,7 @@ end function reinterpret{T,Tv,Ti}(::Type{T}, a::SparseMatrixCSC{Tv,Ti}) if sizeof(T) != sizeof(Tv) - error("SparseMatrixCSC reinterpret is only supported for element types of the same size") + throw(ArgumentError("SparseMatrixCSC reinterpret is only supported for element types of the same size")) end mA, nA = size(a) colptr = copy(a.colptr) @@ -76,10 +77,10 @@ end function reinterpret{T,Tv,Ti,N}(::Type{T}, a::SparseMatrixCSC{Tv,Ti}, dims::NTuple{N,Int}) if sizeof(T) != sizeof(Tv) - error("SparseMatrixCSC reinterpret is only supported for element types of the same size") + throw(ArgumentError("SparseMatrixCSC reinterpret is only supported for element types of the same size")) end if prod(dims) != length(a) - error("new dimensions $(dims) must be consistent with array size $(length(a))") + throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $(length(a))")) end mS,nS = dims mA,nA = size(a) @@ -95,7 +96,7 @@ end function reshape{Tv,Ti}(a::SparseMatrixCSC{Tv,Ti}, dims::NTuple{2,Int}) if prod(dims) != length(a) - error("new dimensions $(dims) must be consistent with array size $(length(a))") + throw(DimensionMismatch("new dimensions $(dims) must be consistent with array size $(length(a))")) end mS,nS = dims mA,nA = size(a) @@ -184,6 +185,7 @@ function sparsevec(I::AbstractVector, V, m::Integer, combine::Function) if isa(V, Number); V = fill(V, nI); end p = sortperm(I) I = I[p] + m >= I[end] || throw(DimensionMismatch("indices cannot be larger than length of vector")) V = V[p] sparse_IJ_sorted!(I, ones(Int, nI), V, m, 1, combine) end @@ -327,7 +329,7 @@ function findnz{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti}) end function sprand(m::Integer, n::Integer, density::FloatingPoint, rng::Function, v) - 0 <= density <= 1 || error("density must be between 0 and 1") + 0 <= density <= 1 || throw(ArgumentError("density must be between 0 and 1")) N = n*m # if density < 0.5, we'll randomly generate the indices to set # otherwise, we'll randomly generate the indices to skip @@ -408,7 +410,7 @@ end function one{T}(S::SparseMatrixCSC{T}) m,n = size(S) - if m != n; error("multiplicative identity only defined for square matrices"); end + if m != n; throw(DimensionMismatch("multiplicative identity only defined for square matrices")); end speye(T, m) end @@ -445,7 +447,7 @@ for (op, restype) in ( (:+, Nothing), (:-, Nothing), (:.*, Nothing), (:.^, Nothi function ($op){Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, B::SparseMatrixCSC{Tv,Ti}) if size(A,1) != size(B,1) || size(A,2) != size(B,2) - error("incompatible sizes") + throw(DimensionMismatch("")) end (m, n) = size(A) @@ -613,17 +615,17 @@ function reducedim{Tv,Ti}(f::Function, A::SparseMatrixCSC{Tv,Ti}, region, v0) return [S] else - error("invalid value for region; must be 1, 2, or (1,2)") + throw(ArgumentError("invalid value for region; must be 1, 2, or (1,2)")) end end maximum{T}(A::SparseMatrixCSC{T}) = - isempty(A) ? error("argument must not be empty") : reducedim(scalarmax,A,(1,2),typemin(T)) + isempty(A) ? throw(ArgumentError("argument must not be empty")) : reducedim(scalarmax,A,(1,2),typemin(T)) maximum{T}(A::SparseMatrixCSC{T}, region) = isempty(A) ? similar(A, reduced_dims0(A,region)) : reducedim(scalarmax,A,region,typemin(T)) minimum{T}(A::SparseMatrixCSC{T}) = - isempty(A) ? error("argument must not be empty") : reducedim(scalarmin,A,(1,2),typemax(T)) + isempty(A) ? throw(ArgumentError("argument must not be empty")) : reducedim(scalarmin,A,(1,2),typemax(T)) minimum{T}(A::SparseMatrixCSC{T}, region) = isempty(A) ? similar(A, reduced_dims0(A,region)) : reducedim(scalarmin,A,region,typemax(T)) @@ -643,7 +645,7 @@ getindex(A::SparseMatrixCSC, i::Integer) = getindex(A, ind2sub(size(A),i)) getindex(A::SparseMatrixCSC, I::(Integer,Integer)) = getindex(A, I[1], I[2]) function getindex{T}(A::SparseMatrixCSC{T}, i0::Integer, i1::Integer) - if !(1 <= i0 <= A.m && 1 <= i1 <= A.n); error(BoundsError); end + if !(1 <= i0 <= A.m && 1 <= i1 <= A.n); throw(BoundsError()); end first = A.colptr[i1] last = A.colptr[i1+1]-1 while first <= last @@ -954,7 +956,7 @@ setindex!(A::SparseMatrixCSC, v, i::Integer) = setindex!(A, v, ind2sub(size(A),i function setindex!{T,Ti}(A::SparseMatrixCSC{T,Ti}, v, i0::Integer, i1::Integer) i0 = convert(Ti, i0) i1 = convert(Ti, i1) - if !(1 <= i0 <= A.m && 1 <= i1 <= A.n); error(BoundsError); end + if !(1 <= i0 <= A.m && 1 <= i1 <= A.n); throw(BoundsError()); end v = convert(T, v) if v == 0 #either do nothing or delete entry if it exists first = A.colptr[i1] @@ -1068,7 +1070,7 @@ setindex!{Tv,Ti,T<:Integer}(A::SparseMatrixCSC{Tv,Ti}, S::Matrix, I::AbstractVec # A[I,J] = B function setindex!{Tv,Ti,T<:Integer}(A::SparseMatrixCSC{Tv,Ti}, B::SparseMatrixCSC{Tv,Ti}, I::AbstractVector{T}, J::AbstractVector{T}) if size(B,1) != length(I) || size(B,2) != length(J) - error("dimensions must match") + throw(DimensionMismatch("")) end issortedI = issorted(I) @@ -1205,7 +1207,7 @@ function vcat(X::SparseMatrixCSC...) nX = [ size(x, 2) for x in X ] n = nX[1] for i = 2 : num - if nX[i] != n; error("dimensions must match"); end + if nX[i] != n; throw(DimensionMismatch("")); end end m = sum(mX) @@ -1243,7 +1245,7 @@ function hcat(X::SparseMatrixCSC...) nX = [ size(x, 2) for x in X ] m = mX[1] for i = 2 : num - if mX[i] != m; error("dimensions must match"); end + if mX[i] != m; throw(DimensionMismatch("")); end end n = sum(nX) @@ -1379,7 +1381,7 @@ spdiagm(B::AbstractVector, d::Number=0) = spdiagm((B,), (d,)) ## expand a colptr or rowptr into a dense index vector function expandptr{T<:Integer}(V::Vector{T}) - if V[1] != 1 error("first index must be one") end + if V[1] != 1 throw(ArgumentError("first index must be one")) end res = similar(V, (int64(V[end]-1),)) for i in 1:(length(V)-1), j in V[i]:(V[i+1] - 1) res[j] = i end res @@ -1417,7 +1419,7 @@ end function trace{Tv}(A::SparseMatrixCSC{Tv}) if size(A,1) != size(A,2) - error("expected square matrix") + throw(DimensionMismatch("expected square matrix")) end s = zero(Tv) for d in SpDiagIterator(A) @@ -1430,7 +1432,7 @@ diag(A::SparseMatrixCSC) = [d for d in SpDiagIterator(A)] function diagm{Tv,Ti}(v::SparseMatrixCSC{Tv,Ti}) if (size(v,1) != 1 && size(v,2) != 1) - error("input should be nx1 or 1xn") + throw(DimensionMismatch("input should be nx1 or 1xn")) end n = length(v) diff --git a/test/sparse.jl b/test/sparse.jl index 99255999f01e6..b33861e92c83b 100644 --- a/test/sparse.jl +++ b/test/sparse.jl @@ -176,3 +176,6 @@ P,post = Base.LinAlg.etree(A, true) sfe22 = speye(Float64, 2) mfe22 = eye(Float64, 2) @test reinterpret(Int64, sfe22) == reinterpret(Int64, mfe22) + +# Issue 5190 +@test_throws sparsevec([3,5,7],[0.1,0.0,3.2],4) From 9cb1b5cd8b170650e83f3487435da12e94a3ab7a Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 21 Dec 2013 17:35:08 -0500 Subject: [PATCH 73/89] remove use of callback API in REPL --- base/client.jl | 45 ++++++++++++++------------------------------- base/precompile.jl | 1 - 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/base/client.jl b/base/client.jl index 0eae856db9670..4efa6d002235d 100644 --- a/base/client.jl +++ b/base/client.jl @@ -37,13 +37,6 @@ exit(n) = ccall(:jl_exit, Void, (Int32,), n) exit() = exit(0) quit() = exit() -function repl_callback(ast::ANY, show_value) - global _repl_enough_stdin = true - stop_reading(STDIN) - STDIN.readcb = false - put(repl_channel, (ast, show_value)) -end - function repl_cmd(cmd) shell = shell_split(get(ENV,"JULIA_SHELL",get(ENV,"SHELL","/bin/sh"))) # Note that we can't support the fish shell due to its lack of subshells @@ -144,28 +137,9 @@ function eval_user_input(ast::ANY, show_value) isa(STDIN,TTY) && println() end -function read_buffer(stream::AsyncStream, nread) - global _repl_enough_stdin::Bool - while !_repl_enough_stdin && nb_available(stream.buffer) > 0 - nread = int(search(stream.buffer,'\n')) # never more than one line or readline explodes :O - nread2 = int(search(stream.buffer,'\r')) - if nread == 0 - if nread2 == 0 - nread = nb_available(stream.buffer) - else - nread = nread2 - end - else - if nread2 != 0 && nread2 < nread - nread = nread2 - end - end - ptr = pointer(stream.buffer.data,stream.buffer.ptr) - skip(stream.buffer,nread) - #println(STDERR,stream.buffer.data[stream.buffer.ptr-nread:stream.buffer.ptr-1]) - ccall(:jl_read_buffer,Void,(Ptr{Void},Cssize_t),ptr,nread) - end - return false +function repl_callback(ast::ANY, show_value) + global _repl_enough_stdin = true + put(repl_channel, (ast, show_value)) end function run_repl() @@ -175,7 +149,17 @@ function run_repl() # install Ctrl-C interrupt handler (InterruptException) ccall(:jl_install_sigint_handler, Void, ()) - STDIN.closecb = (x...)->put(repl_channel,(nothing,-1)) + buf = Uint8[0] + @async begin + while !eof(STDIN) + read(STDIN, buf) + ccall(:jl_read_buffer,Void,(Ptr{Void},Cssize_t),buf,1) + if _repl_enough_stdin + yield() + end + end + put(repl_channel,(nothing,-1)) + end while true if have_color @@ -185,7 +169,6 @@ function run_repl() end ccall(:repl_callback_enable, Void, (Ptr{Uint8},), prompt_string) global _repl_enough_stdin = false - start_reading(STDIN, read_buffer) (ast, show_value) = take(repl_channel) if show_value == -1 # exit flag diff --git a/base/precompile.jl b/base/precompile.jl index c999d3df4358f..bebe27e4c7e76 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -138,7 +138,6 @@ precompile(task_local_storage, ()) precompile(atexit, (Function,)) precompile(print, (TTY, ASCIIString)) precompile(close, (TTY,)) -precompile(read_buffer, (TTY,Int)) precompile(put, (RemoteRef, Any)) precompile(getpid, ()) precompile(print, (IOStream, Int32)) From 74a130d6d404196b16995c4c9b52678050c02de2 Mon Sep 17 00:00:00 2001 From: Dahua Lin Date: Sat, 21 Dec 2013 16:41:59 -0600 Subject: [PATCH 74/89] specialized abs2 for bool --- base/bool.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/base/bool.jl b/base/bool.jl index be71393f9f083..38223f7e46dc5 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -26,6 +26,7 @@ typemax(::Type{Bool}) = true signbit(x::Bool) = 0 sign(x::Bool) = x abs(x::Bool) = x +abs2(x::Bool) = x <(x::Bool, y::Bool) = y&!x <=(x::Bool, y::Bool) = y|!x From 82a4de121919071768f87dc24a1d53275d3d1dde Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 21 Dec 2013 18:00:52 -0500 Subject: [PATCH 75/89] clean up native finalizers code --- base/gmp.jl | 4 ---- base/mpfr.jl | 1 - src/gc.c | 4 ++-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/base/gmp.jl b/base/gmp.jl index 6ba77ef504272..e13c835a20048 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -21,10 +21,6 @@ type BigInt <: Integer end end -function BigInt_clear(mpz::BigInt) - ccall((:__gmpz_clear, :libgmp), Void, (Ptr{BigInt},), &mpz) -end - _gmp_clear_func = C_NULL _mpfr_clear_func = C_NULL diff --git a/base/mpfr.jl b/base/mpfr.jl index a0a84cde812a6..6f2b866134c58 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -45,7 +45,6 @@ type BigFloat <: FloatingPoint new(prec, sign, exp, d) end end -MPFR_clear(mpfr::BigFloat) = ccall((:mpfr_clear, :libmpfr), Void, (Ptr{BigFloat},), &mpfr) BigFloat(x::BigFloat) = x diff --git a/src/gc.c b/src/gc.c index 4ec8b664ef6f5..d77515a2b0e5d 100644 --- a/src/gc.c +++ b/src/gc.c @@ -864,9 +864,9 @@ static void gc_mark(void) if (!gc_marked(v)) { jl_value_t *fin = finalizer_table.table[i+1]; if (gc_typeof(fin) == (jl_value_t*)jl_voidpointer_type) { - void *p = ((void**)fin)[1]; + void *p = jl_unbox_voidpointer(fin); if (p) - ((void (*)(void*))p)(&((void**)v)[1]); + ((void (*)(void*))p)(jl_data_ptr(v)); finalizer_table.table[i+1] = HT_NOTFOUND; continue; } From 90f4fc4fab54c0737d89f6c0637b49d8be00c07b Mon Sep 17 00:00:00 2001 From: Isaiah Date: Sun, 22 Dec 2013 02:46:38 -0500 Subject: [PATCH 76/89] doc: `import M: single,name` syntax, close #5214 --- doc/manual/modules.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/manual/modules.rst b/doc/manual/modules.rst index 7619624602880..615817fc74d5a 100644 --- a/doc/manual/modules.rst +++ b/doc/manual/modules.rst @@ -19,6 +19,8 @@ not meant to be run, but is shown for illustrative purposes:: module MyModule using Lib + import BigLib: bar, baz + export MyType, foo type MyType @@ -47,6 +49,9 @@ will search for it in ``Lib`` and import it if it is found there. This means that all uses of that global within the current module will resolve to the definition of that variable in ``Lib``. +The statement ``import BigLib: bar, baz`` means that the names `bar` and `baz` +from the `BigLib` module will be available as needed (but no other names). + Once a variable is imported this way (or, equivalently, with the ``import`` keyword), a module may not create its own variable with the same name. Imported variables are read-only; assigning to a global variable always From ab372c371f016a0e3854c5612e3dc4849aa5beb3 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Sun, 22 Dec 2013 08:35:32 -0500 Subject: [PATCH 77/89] update NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index cbbb825042d1b..7a314ee5b27f7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ New language features * Tuples (of integers, symbols, or bools) can now be used as type parameters ([#5164]). + * `import module: name1, name2, ...` ([#5214]). + New library functions --------------------- From 8d10edf59cd79339d471115e5461fc44546167ec Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Sat, 30 Nov 2013 17:14:46 -0500 Subject: [PATCH 78/89] add text/html writemime for MethodList and Method (fix #4952) --- base/methodshow.jl | 134 +++++++++++++++++++++++++++++++++++++++++++++ base/show.jl | 76 ------------------------- base/sysimg.jl | 1 + 3 files changed, 135 insertions(+), 76 deletions(-) create mode 100644 base/methodshow.jl diff --git a/base/methodshow.jl b/base/methodshow.jl new file mode 100644 index 0000000000000..5ea0f129703f1 --- /dev/null +++ b/base/methodshow.jl @@ -0,0 +1,134 @@ +# Method and method-table pretty-printing + +function argtype_decl(n, t) # -> (argname, argtype) + if isa(n,Expr) + n = n.args[1] # handle n::T in arg list + end + s = string(n) + i = search(s,'#') + if i > 0 + s = s[1:i-1] + end + if t === Any && !isempty(s) + return s, "" + end + if t <: Vararg && t !== None && t.parameters[1] === Any + return string(s, "..."), "" + end + return s, string(t) +end + +function arg_decl_parts(m::Method) + tv = m.tvars + if !isa(tv,Tuple) + tv = (tv,) + end + li = m.func.code + e = uncompressed_ast(li) + argnames = e.args[1] + s = symbol("?") + decls = [argtype_decl(get(argnames,i,s), m.sig[i]) for i=1:length(m.sig)] + return tv, decls, li.file, li.line +end + +function show(io::IO, m::Method) + tv, decls, file, line = arg_decl_parts(m) + if !isempty(tv) + show_delim_array(io, tv, '{', ',', '}', false) + end + print(io, "(") + print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2] for d in decls], + ",", ",") + print(io, ")") + if line > 0 + print(io, " at ", file, ":", line) + end +end + +function show_method_table(io::IO, mt::MethodTable, max::Int=-1, header::Bool=true) + name = mt.name + n = length(mt) + if header + m = n==1 ? "method" : "methods" + print(io, "# $n $m for generic function \"$name\":") + end + d = mt.defs + n = rest = 0 + while !is(d,()) + if max==-1 || n 0 + println(io) + print(io,"... $rest methods not shown (use methods($name) to see them all)") + end +end + +show(io::IO, mt::MethodTable) = show_method_table(io, mt) + +inbase(m::Module) = m == Base ? true : m == Main ? false : inbase(module_parent(m)) +function url(m::Method) + M = m.func.code.module + file = string(m.func.code.file) + line = m.func.code.line + line <= 0 || ismatch(r"In\[[0-9]+\]", file) && return "" + if inbase(M) + return "https://github.com/JuliaLang/julia/tree/$(Base.BUILD_INFO.commit)/base/$file#L$line" + else + try + pkg = Pkg.dir(string(M)) + if file[1:length(pkg)] != pkg + return "file://"*find_source_file(file) + end + u = Git.readchomp(`config remote.origin.url`, dir=pkg) + u = match(Git.GITHUB_REGEX,u).captures[1] + commit = Git.readchomp(`rev-parse HEAD`, dir=pkg) + return "https://github.com/$u/tree/$commit/"*file[length(pkg)+2:end]*"#L$line" + catch + return "file://"*find_source_file(file) + end + end +end + +function writemime(io::IO, ::MIME"text/html", m::Method) + tv, decls, file, line = arg_decl_parts(m) + if !isempty(tv) + print(io,"") + show_delim_array(io, tv, '{', ',', '}', false) + print(io,"") + end + print(io, "(") + print_joined(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2]*"" + for d in decls], ",", ",") + print(io, ")") + if line > 0 + u = url(m) + if isempty(u) + print(io, " at ", file, ":", line) + else + print(io, """ at """, + file, ":", line, "") + end + end +end + +function writemime(io::IO, mime::MIME"text/html", mt::MethodTable) + name = mt.name + n = length(mt) + meths = n==1 ? "method" : "methods" + print(io, "$n $meths for generic function $name:
    ") + d = mt.defs + while !is(d,()) + print(io, "
  • ", name) + writemime(io, mime, d) + d = d.next + end + print(io, "
") +end diff --git a/base/show.jl b/base/show.jl index c05a0f60aff3a..d8b0aadd35187 100644 --- a/base/show.jl +++ b/base/show.jl @@ -388,82 +388,6 @@ function show_unquoted(io::IO, ex::SymbolNode) show_expr_type(io, ex.typ) end -function clean_gensym(s::Symbol) - s = string(s) - i = search(s,'#') - if i > 0 - return s[1:i-1] - end - return s -end - -function argtype_decl_string(n, t) - if isa(n,Expr) - n = n.args[1] # handle n::T in arg list - end - n = clean_gensym(n) - if t === Any && !isempty(n) - return n - end - if t <: Vararg && t !== None && t.parameters[1] === Any - return string(n, "...") - end - return string(n, "::", t) -end - -function show(io::IO, m::Method) - tv = m.tvars - if !isa(tv,Tuple) - tv = (tv,) - end - if !isempty(tv) - show_delim_array(io, tv, '{', ',', '}', false) - end - li = m.func.code - e = uncompressed_ast(li) - argnames = e.args[1] - if length(argnames) != length(m.sig) - s = symbol("?") - decls = map(argtype_decl_string, { s for i=1:length(m.sig) }, {m.sig...}) - else - decls = map(argtype_decl_string, argnames, {m.sig...}) - end - print(io, "(") - print_joined(io, decls, ",", ",") - print(io, ")") - if li.line > 0 - print(io, " at ", li.file, ":", li.line) - end -end - -function show_method_table(io::IO, mt::MethodTable, max::Int=-1, header::Bool=true) - name = mt.name - n = length(mt) - if header - m = n==1 ? "method" : "methods" - print(io, "# $n $m for generic function \"$name\":") - end - d = mt.defs - n = rest = 0 - while !is(d,()) - if max==-1 || n 0 - println(io) - print(io,"... $rest methods not shown (use methods($name) to see them all)") - end -end - -show(io::IO, mt::MethodTable) = show_method_table(io, mt) - # dump & xdump - structured tree representation like R's str() # - dump is for the user-facing structure # - xdump is for the internal structure diff --git a/base/sysimg.jl b/base/sysimg.jl index 7d7a4e4e6b746..e5da016db2fba 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -105,6 +105,7 @@ import .Grisu.print_shortest include("printf.jl") importall .Printf include("file.jl") +include("methodshow.jl") # core math functions include("floatfuncs.jl") From 4861ee2cced89f9249f07c13d23c7d46dbe30551 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Sun, 1 Dec 2013 11:31:03 -0500 Subject: [PATCH 79/89] hopefully more robust way of getting github URL (don't assume module name is Pkg name) --- base/methodshow.jl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/base/methodshow.jl b/base/methodshow.jl index 5ea0f129703f1..611686c067db6 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -83,14 +83,18 @@ function url(m::Method) return "https://github.com/JuliaLang/julia/tree/$(Base.BUILD_INFO.commit)/base/$file#L$line" else try - pkg = Pkg.dir(string(M)) - if file[1:length(pkg)] != pkg + d = dirname(file) + u = Git.readchomp(`config remote.origin.url`, dir=d) + u = match(Git.GITHUB_REGEX,u).captures[1] + root = cd(d) do # dir=d confuses --show-toplevel, apparently + Git.readchomp(`rev-parse --show-toplevel`) + end + if beginswith(file, root) + commit = Git.readchomp(`rev-parse HEAD`, dir=d) + return "https://github.com/$u/tree/$commit/"*file[length(root)+2:end]*"#L$line" + else return "file://"*find_source_file(file) end - u = Git.readchomp(`config remote.origin.url`, dir=pkg) - u = match(Git.GITHUB_REGEX,u).captures[1] - commit = Git.readchomp(`rev-parse HEAD`, dir=pkg) - return "https://github.com/$u/tree/$commit/"*file[length(pkg)+2:end]*"#L$line" catch return "file://"*find_source_file(file) end From 426c80acdcefe845e119e35f68a6eed0a778bd46 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Sun, 22 Dec 2013 09:20:34 -0500 Subject: [PATCH 80/89] silence compiler warning --- src/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.c b/src/init.c index 2f8952dffe8c0..49f539bdd4f12 100644 --- a/src/init.c +++ b/src/init.c @@ -591,7 +591,7 @@ kern_return_t catch_exception_raise(mach_port_t exception_port, ret = thread_get_state(thread,x86_EXCEPTION_STATE64,(thread_state_t)&exc_state,&exc_count); HANDLE_MACH_ERROR("thread_get_state(1)",ret); uint64_t fault_addr = exc_state.__faultvaddr; - if (is_addr_on_stack(fault_addr)) { + if (is_addr_on_stack((void*) fault_addr)) { ret = thread_get_state(thread,x86_THREAD_STATE64,(thread_state_t)&state,&count); HANDLE_MACH_ERROR("thread_get_state(2)",ret); old_state = state; From 360368840c3f2d6425d98274fb0ac62c8af92e7a Mon Sep 17 00:00:00 2001 From: timholy Date: Sun, 22 Dec 2013 12:12:43 -0600 Subject: [PATCH 81/89] Fix #5217 --- base/graphics.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/base/graphics.jl b/base/graphics.jl index a378abdf3e370..0722fe750aed8 100644 --- a/base/graphics.jl +++ b/base/graphics.jl @@ -83,9 +83,6 @@ end BoundingBox() = BoundingBox(NaN, NaN, NaN, NaN) -BoundingBox(a::Real, b::Real, c::Real, d::Real) = - BoundingBox(float64(a), float64(b), float64(c), float64(d)) - function BoundingBox(points::Point...) xmin, xmax, ymin, ymax = NaN, NaN, NaN, NaN for p in points From 748996ca5a647a04cf9e2aa1d61ea04280225834 Mon Sep 17 00:00:00 2001 From: Dahua Lin Date: Sun, 22 Dec 2013 13:45:10 -0600 Subject: [PATCH 82/89] minor update of hypot to ensure consistency of output types --- base/math.jl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/base/math.jl b/base/math.jl index b9c93e9c41f83..20720f719bf27 100644 --- a/base/math.jl +++ b/base/math.jl @@ -240,21 +240,6 @@ end log(b,x) = log(x)./log(b) -hypot(x::Real, y::Real) = hypot(promote(x,y)...) -function hypot{T<:Real}(x::T, y::T) - x = abs(x) - y = abs(y) - if x < y - x, y = y, x - end - if x == 0 - r = y/one(x) - else - r = y/x - end - x * sqrt(one(r)+r*r) -end - # type specific math functions const libm = Base.libm_name @@ -308,6 +293,21 @@ round(x::Float32) = ccall((:roundf, libm), Float32, (Float32,), x) floor(x::Float32) = ccall((:floorf, libm), Float32, (Float32,), x) @vectorize_1arg Real floor +hypot(x::Real, y::Real) = hypot(promote(float(x), float(y))...) +function hypot{T<:FloatingPoint}(x::T, y::T) + x = abs(x) + y = abs(y) + if x < y + x, y = y, x + end + if x == 0 + r = y/one(x) + else + r = y/x + end + x * sqrt(one(r)+r*r) +end + atan2(x::Real, y::Real) = atan2(promote(float(x),float(y))...) atan2{T<:FloatingPoint}(x::T, y::T) = Base.no_op_err("atan2", T) From bc2693ea1905d0de6ec72c3eac4b6233f881e241 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sun, 22 Dec 2013 15:14:47 -0500 Subject: [PATCH 83/89] only show ccall literal address warning in imaging mode. closes #5215 --- src/ccall.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ccall.cpp b/src/ccall.cpp index a9b709b9a4e9f..01ff9d9e76667 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -512,7 +512,8 @@ static Value *emit_cglobal(jl_value_t **args, size_t nargs, jl_codectx_t *ctx) } else if (sym.fptr != NULL) { res = literal_static_pointer_val(sym.fptr, lrt); - JL_PRINTF(JL_STDERR,"warning: literal address used in cglobal for %s; code cannot be statically compiled\n", sym.f_name); + if (imaging_mode) + JL_PRINTF(JL_STDERR,"warning: literal address used in cglobal for %s; code cannot be statically compiled\n", sym.f_name); } else { if (imaging_mode) { @@ -858,7 +859,8 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx) else if (fptr != NULL) { Type *funcptype = PointerType::get(functype,0); llvmf = literal_static_pointer_val(fptr, funcptype); - JL_PRINTF(JL_STDERR,"warning: literal address used in ccall for %s; code cannot be statically compiled\n", f_name); + if (imaging_mode) + JL_PRINTF(JL_STDERR,"warning: literal address used in ccall for %s; code cannot be statically compiled\n", f_name); } else { assert(f_name != NULL); From d0d4514358bbed006de6458272c79af4a1f84bba Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sun, 22 Dec 2013 15:19:07 -0500 Subject: [PATCH 84/89] fix doc for && and || and update helpdb --- doc/helpdb.jl | 274 ++++++++++++++++++++++++++++---------------- doc/stdlib/base.rst | 8 +- 2 files changed, 180 insertions(+), 102 deletions(-) diff --git a/doc/helpdb.jl b/doc/helpdb.jl index a7ecacd223f42..b34cf05bc2bb7 100644 --- a/doc/helpdb.jl +++ b/doc/helpdb.jl @@ -482,7 +482,7 @@ information about a struct type: structinfo(T) = [zip(fieldoffsets(T),names(T),T.types)...] - structinfo(Stat) + structinfo(StatStruct) "), @@ -530,6 +530,18 @@ "), +("Generic Functions","Base","apply","apply(f, x...) + + Accepts a function and several arguments, each of which must be + iterable. The elements generated by all the arguments are appended + into a single list, which is then passed to \"f\" as its argument + list. \"apply\" is called to implement the \"...\" argument + splicing syntax, and is usually not called directly. + + **Example**: \"apply(f,x) === f(x...)\" + +"), + ("Generic Functions","Base","method_exists","method_exists(f, tuple) -> Bool Determine whether the given generic function has a method matching @@ -610,7 +622,7 @@ "), -("Syntax","Base","parse","parse(str, [start]; greedy=true, raise=false) +("Syntax","Base","parse","parse(str, start; greedy=true, raise=true) Parse the expression string and return an expression (which could later be passed to eval for execution). Start is the index of the @@ -622,6 +634,14 @@ "), +("Syntax","Base","parse","parse(str; raise=true) + + Parse the whole string greedily, returning a single expression. An + error is thrown if there are additional characters after the first + expression. + +"), + ("Iteration","Base","start","start(iter) -> state Get initial iteration state for an iterable object @@ -691,8 +711,10 @@ ("Iterable Collections","Base","in","in(item, collection) -> Bool Determine whether an item is in the given collection, in the sense - that it is \"isequal\" to one of the values generated by iterating - over the collection. + that it is \"==\" to one of the values generated by iterating over + the collection. Some collections need a slightly different + definition; for example Sets and Dicts check whether the item is + \"isequal\" to one of the keys. "), @@ -729,16 +751,34 @@ ("Iterable Collections","Base","reduce","reduce(op, v0, itr) - Reduce the given collection with the given operator, i.e. - accumulate \"v = op(v,elt)\" for each element, where \"v\" starts - as \"v0\". Reductions for certain commonly-used operators are - available in a more convenient 1-argument form: \"maximum(itr)\", + Reduce the given collection \"ìtr\" with the given binary operator. + Reductions for certain commonly-used operators are available in a + more convenient 1-argument form: \"maximum(itr)\", \"minimum(itr)\", \"sum(itr)\", \"prod(itr)\", \"any(itr)\", \"all(itr)\". - The associativity of the reduction is implementation-dependent; if - you need a particular associativity, e.g. left-to-right, you should - write your own loop. + The associativity of the reduction is implementation-dependent. + This means that you can't use non-associative operations like \"-\" + because it is undefined whether \"reduce(-,[1,2,3])\" should be + evaluated as \"(1-2)-3\" or \"1-(2-3)\". Use \"foldl\" or \"foldr\" + instead for guaranteed left or right associativity. + + Some operations accumulate error, and parallelism will also be + easier if the reduction can be executed in groups. Future versions + of Julia might change the algorithm. Note that the elements are not + reordered if you use an ordered collection. + +"), + +("Iterable Collections","Base","foldl","foldl(op, v0, itr) + + Like \"reduce\", but with guaranteed left associativity. + +"), + +("Iterable Collections","Base","foldr","foldr(op, v0, itr) + + Like \"reduce\", but with guaranteed right associativity. "), @@ -850,21 +890,23 @@ ("Iterable Collections","Base","count","count(p, itr) -> Integer Count the number of elements in \"itr\" for which predicate \"p\" - is true. + returns true. "), ("Iterable Collections","Base","any","any(p, itr) -> Bool - Determine whether any element of \"itr\" satisfies the given - predicate. + Determine whether predicate \"p\" returns true for any elements of + \"itr\". "), ("Iterable Collections","Base","all","all(p, itr) -> Bool - Determine whether all elements of \"itr\" satisfy the given - predicate. + Determine whether predicate \"p\" returns true for all elements of + \"itr\". + + **Example**: \"all((i) -> i>i, [4,5,6]) = true\" "), @@ -891,7 +933,7 @@ The associativity of the reduction is implementation-dependent; if you need a particular associativity, e.g. left-to-right, you should - write your own loop. + write your own loop. See documentation for \"reduce\". "), @@ -1549,15 +1591,15 @@ ("Strings","Base","nextind","nextind(str, i) - Get the next valid string index after \"i\". Returns - \"endof(str)+1\" at the end of the string. + Get the next valid string index after \"i\". Returns a value + greater than \"endof(str)\" at or after the end of the string. "), ("Strings","Base","prevind","prevind(str, i) - Get the previous valid string index before \"i\". Returns \"0\" at - the beginning of the string. + Get the previous valid string index before \"i\". Returns a value + less than \"1\" at the beginning of the string. "), @@ -2910,6 +2952,27 @@ popdisplay(d::Display) "), +("Mathematical Operators","Base","modpi","modpi(x) + + Modulus after division by pi, returning in the range [0,pi). More + accurate than mod(x,pi). + +"), + +("Mathematical Operators","Base","mod2pi","mod2pi(x) + + Modulus after division by 2pi, returning in the range [0,2pi). More + accurate than mod(x,2pi). + +"), + +("Mathematical Operators","Base","modpio2","modpio2(x) + + Modulus after division by pi/2, returning in the range [0,pi/2). + More accurate than mod(x,pi/2). + +"), + ("Mathematical Operators","Base","rem","rem(x, m) Remainder after division @@ -3127,15 +3190,15 @@ popdisplay(d::Display) "), -("Mathematical Operators","Base","&&","&&(x, y) +("Mathematical Operators","","x && y","x && y - Boolean and + Short-circuiting boolean and "), -("Mathematical Operators","Base","||","||(x, y) +("Mathematical Operators","","x || y","x || y - Boolean or + Short-circuiting boolean or "), @@ -3556,6 +3619,13 @@ popdisplay(d::Display) "), +("Mathematical Functions","Base","log","log(b, x) + + Compute the base \"b\" logarithm of \"x\". Throws \"DomainError\" + for negative \"Real\" arguments. + +"), + ("Mathematical Functions","Base","log2","log2(x) Compute the logarithm of \"x\" to base 2. Throws \"DomainError\" @@ -3627,7 +3697,7 @@ popdisplay(d::Display) \"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)\" + using a different base, defaulting to 10, e.g., \"round(pi, 1, 8)\" is \"3.125\". "), @@ -3754,9 +3824,10 @@ popdisplay(d::Display) "), -("Mathematical Functions","Base","isqrt","isqrt(x) +("Mathematical Functions","Base","isqrt","isqrt(n) - Integer square root. + Integer square root: the largest integer \"m\" such that \"m*m <= + n\". "), @@ -3914,25 +3985,31 @@ popdisplay(d::Display) ("Mathematical Functions","Base","nextpow2","nextpow2(n) - Next power of two not less than \"n\" + The smallest power of two not less than \"n\". Returns 0 for + \"n==0\", and returns \"-nextpow2(-n)\" for negative arguments. "), ("Mathematical Functions","Base","prevpow2","prevpow2(n) - Previous power of two not greater than \"n\" + The largest power of two not greater than \"n\". Returns 0 for + \"n==0\", and returns \"-prevpow2(-n)\" for negative arguments. "), -("Mathematical Functions","Base","nextpow","nextpow(a, n) +("Mathematical Functions","Base","nextpow","nextpow(a, x) - Next power of \"a\" not less than \"n\" + The smallest \"a^n\" not less than \"x\", where \"n\" is a non- + negative integer. \"a\" must be greater than 1, and \"x\" must be + greater than 0. "), -("Mathematical Functions","Base","prevpow","prevpow(a, n) +("Mathematical Functions","Base","prevpow","prevpow(a, x) - Previous power of \"a\" not greater than \"n\" + The largest \"a^n\" not greater than \"x\", where \"n\" is a non- + negative integer. \"a\" must be greater than 1, and \"x\" must not + be less than 1. "), @@ -4606,29 +4683,32 @@ popdisplay(d::Display) "), -("Numbers","Base","get_rounding","get_rounding() +("Numbers","Base","get_rounding","get_rounding(T) - Get the current floating point rounding mode. Valid modes are - \"RoundNearest\", \"RoundToZero\", \"RoundUp\" and \"RoundDown\". + Get the current floating point rounding mode for type \"T\". Valid + modes are \"RoundNearest\", \"RoundToZero\", \"RoundUp\", + \"RoundDown\", and \"RoundFromZero\" (\"BigFloat\" only). "), -("Numbers","Base","set_rounding","set_rounding(mode) +("Numbers","Base","set_rounding","set_rounding(T, mode) - Set the floating point rounding mode. See \"get_rounding\" for - available modes + Set the rounding mode of floating point type \"T\". Note that this + may affect other types, for instance changing the rounding mode of + \"Float64\" will change the rounding mode of \"Float32\". See + \"get_rounding\" for available modes "), -("Numbers","Base","with_rounding","with_rounding(f::Function, mode) +("Numbers","Base","with_rounding","with_rounding(f::Function, T, mode) - Change the floating point rounding mode for the duration of \"f\". - It is logically equivalent to: + Change the rounding mode of floating point type \"T\" for the + duration of \"f\". It is logically equivalent to: - old = get_rounding() - set_rounding(mode) + old = get_rounding(T) + set_rounding(T, mode) f() - set_rounding(old) + set_rounding(T, old) See \"get_rounding\" for available rounding modes. @@ -4745,29 +4825,6 @@ popdisplay(d::Display) "), -("BigFloats","Base","get_bigfloat_rounding","get_bigfloat_rounding() - - Get the current BigFloat rounding mode. Valid modes are - \"RoundNearest\", \"RoundToZero\", \"RoundUp\", \"RoundDown\", - \"RoundFromZero\" - -"), - -("BigFloats","Base","set_bigfloat_rounding","set_bigfloat_rounding(mode) - - Set the BigFloat rounding mode. See get_bigfloat_rounding for - available modes - -"), - -("BigFloats","Base","with_bigfloat_rounding","with_bigfloat_rounding(f::Function, mode) - - Change the BigFloat rounding mode for the duration of \"f\". See - \"get_bigfloat_rounding\" for available rounding modes; see also - \"with_bigfloat_precision\". - -"), - ("Random Numbers","Base","srand","srand([rng], seed) Seed the RNG with a \"seed\", which may be an unsigned integer or a @@ -5256,8 +5313,8 @@ popdisplay(d::Display) ("Arrays","Base","findfirst","findfirst(predicate, A) - Return the index of the first element that satisfies the given - predicate in \"A\". + Return the index of the first element of \"A\" for which + \"predicate\" returns true. "), @@ -5270,8 +5327,8 @@ popdisplay(d::Display) ("Arrays","Base","findnext","findnext(predicate, A, i) - Find the next index >= \"i\" of an element of \"A\" satisfying the - given predicate, or \"0\" if not found. + Find the next index >= \"i\" of an element of \"A\" for which + \"predicate\" returns true, or \"0\" if not found. "), @@ -5395,7 +5452,7 @@ popdisplay(d::Display) The associativity of the reduction is implementation-dependent; if you need a particular associativity, e.g. left-to-right, you should - write your own loop. + write your own loop. See documentation for \"reduce\". "), @@ -5587,6 +5644,18 @@ popdisplay(d::Display) "), +("Combinatorics","Base","partitions","partitions(array, m) + + Generate all set partitions of the elements of an array into + exactly m subsets, represented as arrays of arrays. Because the + number of partitions can be very large, this function returns an + iterator object. Use \"collect(partitions(array,m))\" to get an + array of all partitions. The number of partitions into m subsets is + equal to the Stirling number of the second kind and can be + efficiently computed using \"length(partitions(array,m))\". + +"), + ("Statistics","Base","mean","mean(v[, region]) Compute the mean of whole array \"v\", or optionally along the @@ -7341,16 +7410,19 @@ popdisplay(d::Display) "), -("Tasks","Base","consume","consume(task) +("Tasks","Base","consume","consume(task, values...) Receive the next value passed to \"produce\" by the specified task. + Additional arguments may be passed, to be returned from the last + \"produce\" call in the producer. "), ("Tasks","Base","produce","produce(value) Send the given value to the last \"consume\" call, switching to the - consumer task. + consumer task. If the next \"consume\" call passes any values, they + are returned by \"produce\". "), @@ -8159,8 +8231,8 @@ popdisplay(d::Display) ("Linear Algebra","Base","chol","chol(A[, LU]) -> F Compute Cholesky factorization of a symmetric positive-definite - matrix \"A\" and return the matrix \"F\". If \"LU\" is \"L\" - (Lower), \"A = L*L'\". If \"LU\" is \"U\" (Upper), \"A = R'*R\". + matrix \"A\" and return the matrix \"F\". If \"LU\" is \":L\" + (Lower), \"A = L*L'\". If \"LU\" is \":U\" (Upper), \"A = R'*R\". "), @@ -8168,9 +8240,9 @@ popdisplay(d::Display) Compute the Cholesky factorization of a dense symmetric positive- definite matrix \"A\" and return a \"Cholesky\" object. \"LU\" may - be 'L' for using the lower part or 'U' for the upper part. The - default is to use 'U'. The triangular matrix can be obtained from - the factorization \"F\" with: \"F[:L]\" and \"F[:U]\". The + be \":L\" for using the lower part or \":U\" for the upper part. + The default is to use \":U\". The triangular matrix can be obtained + from the factorization \"F\" with: \"F[:L]\" and \"F[:U]\". The following functions are available for \"Cholesky\" objects: \"size\", \"\\\", \"inv\", \"det\". A \"LAPACK.PosDefException\" error is thrown in case the matrix is not positive definite. @@ -8205,11 +8277,11 @@ popdisplay(d::Display) Compute the pivoted Cholesky factorization of a symmetric positive semi-definite matrix \"A\" and return a \"CholeskyPivoted\" object. - \"LU\" may be 'L' for using the lower part or 'U' for the upper - part. The default is to use 'U'. The triangular factors contained - in the factorization \"F\" can be obtained with \"F[:L]\" and - \"F[:U]\", whereas the permutation can be obtained with \"F[:P]\" - or \"F[:p]\". The following functions are available for + \"LU\" may be \":L\" for using the lower part or \":U\" for the + upper part. The default is to use \":U\". The triangular factors + contained in the factorization \"F\" can be obtained with \"F[:L]\" + and \"F[:U]\", whereas the permutation can be obtained with + \"F[:P]\" or \"F[:p]\". The following functions are available for \"CholeskyPivoted\" objects: \"size\", \"\\\", \"inv\", \"det\". A \"LAPACK.RankDeficientException\" error is thrown in case the matrix is rank deficient. @@ -8547,25 +8619,31 @@ popdisplay(d::Display) "), -("Linear Algebra","Base","scale","scale(A, B) +("Linear Algebra","Base","scale","scale(A, b), scale(b, A) - \"scale(A::Array, B::Number)\" scales all values in \"A\" with - \"B\". Note: In cases where the array is big enough, \"scale\" can - be much faster than \"A .* B\", due to the use of BLAS. + Scale an array \"A\" by a scalar \"b\", returning a new array. - \"scale(A::Matrix, B::Vector)\" is the same as multiplying with a - diagonal matrix on the right, and scales the columns of \"A\" with - the values in \"B\". + If \"A\" is a matrix and \"b\" is a vector, then \"scale!(A,b)\" + scales each column \"i\" of \"A\" by \"b[i]\" (similar to + \"A*diagm(b)\"), while \"scale!(b,A)\" scales each row \"i\" of + \"A\" by \"b[i]\" (similar to \"diagm(b)*A\"), returning a new + array. - \"scale(A::Vector, B::Matrix)\" is the same as multiplying with a - diagonal matrix on the left, and scales the rows of \"B\" with the - values in \"A\". + Note: for large \"A\", \"scale\" can be much faster than \"A .* b\" + or \"b .* A\", due to the use of BLAS. "), -("Linear Algebra","Base","scale!","scale!(A, B) +("Linear Algebra","Base","scale!","scale!(A, b), scale!(b, A) + + Scale an array \"A\" by a scalar \"b\", similar to \"scale\" but + overwriting \"A\" in-place. - \"scale!(A,B)\" overwrites the input array with the scaled result. + If \"A\" is a matrix and \"b\" is a vector, then \"scale!(A,b)\" + scales each column \"i\" of \"A\" by \"b[i]\" (similar to + \"A*diagm(b)\"), while \"scale!(b,A)\" scales each row \"i\" of + \"A\" by \"b[i]\" (similar to \"diagm(b)*A\"), again operating in- + place on \"A\". "), diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index f1c86e238ef40..09a2b2a6a2dfb 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -2195,14 +2195,14 @@ Mathematical Operators Boolean not .. _&&: -.. function:: &&(x, y) +.. function:: x && y - Boolean and + Short-circuiting boolean and .. _||: -.. function:: ||(x, y) +.. function:: x || y - Boolean or + Short-circuiting boolean or .. function:: A_ldiv_Bc(a,b) From af8eae6d4ab9d2099cc0e570bb7daaf5b4ce8c5a Mon Sep 17 00:00:00 2001 From: Dahua Lin Date: Sun, 22 Dec 2013 14:27:47 -0600 Subject: [PATCH 85/89] annotate the types of arguments for derived trigonometric & hyperbolic functions --- base/math.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/base/math.jl b/base/math.jl index 20720f719bf27..c771308690f6b 100644 --- a/base/math.jl +++ b/base/math.jl @@ -152,14 +152,16 @@ for (finv, f) in ((:sec, :cos), (:csc, :sin), (:cot, :tan), (:sech, :cosh), (:csch, :sinh), (:coth, :tanh), (:secd, :cosd), (:cscd, :sind), (:cotd, :tand)) @eval begin - ($finv)(z) = 1 ./ (($f)(z)) + ($finv){T<:Number}(z::T) = one(T) / (($f)(z)) + ($finv){T<:Number}(z::AbstractArray{T}) = one(T) ./ (($f)(z)) end end for (fa, fainv) in ((:asec, :acos), (:acsc, :asin), (:acot, :atan), (:asech, :acosh), (:acsch, :asinh), (:acoth, :atanh)) @eval begin - ($fa)(y) = ($fainv)(1 ./ y) + ($fa){T<:Number}(y::T) = ($fainv)(one(T) / y) + ($fa){T<:Number}(y::AbstractArray{T}) = ($fainv)(one(T) ./ y) end end From 51310bdbeb96e8c2ebc680efc2e7a1a83df7e976 Mon Sep 17 00:00:00 2001 From: Brendan O'Connor Date: Sun, 22 Dec 2013 15:28:07 -0500 Subject: [PATCH 86/89] Add more keywords to ctags regex, plus README --- contrib/README.ctags.txt | 2 ++ contrib/ctags | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 contrib/README.ctags.txt diff --git a/contrib/README.ctags.txt b/contrib/README.ctags.txt new file mode 100644 index 0000000000000..d3f5a28772e84 --- /dev/null +++ b/contrib/README.ctags.txt @@ -0,0 +1,2 @@ +The 'ctags' file is for Exuberant CTags (http://ctags.sourceforge.net/) +Place its contents in your ~/.ctags file. diff --git a/contrib/ctags b/contrib/ctags index ca54ff7d65a78..9b0977a0e627f 100644 --- a/contrib/ctags +++ b/contrib/ctags @@ -1,4 +1,4 @@ --langdef=julia --langmap=julia:.jl ---regex-julia='/^[ \t]*(function|macro)[ \t]+([^ \t({[]+).*$/\2/f,function/' +--regex-julia=/^[ \t]*(function|macro|abstract|type|typealias|immutable)[ \t]+([^ \t({[]+).*$/\2/f,function/ --regex-julia=/^[ \t]*(([^@#$ \t({[]+)|\(([^@#$ \t({[]+)\)|\((\$)\))[ \t]*(\{.*\})?[ \t]*\([^#]*\)[ \t]*=([^=].*$|$)/\2\3\4/f,function/ From 2e9cccb79f9a1cd0c52556b8cf5d9d2d886a9179 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sun, 22 Dec 2013 16:31:22 -0500 Subject: [PATCH 87/89] fix off-by-1 in isqrt. closes #4884 --- base/intfuncs.jl | 4 +++- test/math.jl | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 66af6fbded201..35313e941daf6 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -310,8 +310,10 @@ end isqrt(x::Integer) = oftype(x, trunc(sqrt(x))) function isqrt(x::Union(Int64,Uint64,Int128,Uint128)) + x==0 && return x s = oftype(x, trunc(sqrt(x))) # fix with a Newton iteration, since conversion to float discards # too many bits. - (s + div(x,s)) >> 1 + s = (s + div(x,s)) >> 1 + s*s > x ? s-1 : s end diff --git a/test/math.jl b/test/math.jl index 36af6c891b3e5..a64a67e0f3fa2 100644 --- a/test/math.jl +++ b/test/math.jl @@ -190,3 +190,15 @@ end # isqrt (issue #4884) @test isqrt(9223372030926249000) == 3037000498 @test isqrt(typemax(Int128)) == int128("13043817825332782212") +@test isqrt(int128(typemax(Int64))^2-1) == 9223372036854775806 +@test isqrt(0) == 0 +for i = 1:1000 + n = rand(Uint128) + s = isqrt(n) + @test s*s <= n + @test (s+1)*(s+1) > n + n = rand(Uint64) + s = isqrt(n) + @test s*s <= n + @test (s+1)*(s+1) > n +end From c01e1dbd914209ddafd9fade063e809592a1df63 Mon Sep 17 00:00:00 2001 From: wlbksy Date: Mon, 23 Dec 2013 18:14:43 +0800 Subject: [PATCH 88/89] update pcre --- deps/Versions.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/Versions.make b/deps/Versions.make index 5fa93a9625727..1f82e4424cbe2 100644 --- a/deps/Versions.make +++ b/deps/Versions.make @@ -1,7 +1,7 @@ LLVM_VER = 3.3 LLVM_LIB_SUFFIX = READLINE_VER = 6.2 -PCRE_VER = 8.31 +PCRE_VER = 8.34 GRISU_VER = 1.1.1 DSFMT_VER = 2.2 ifeq ($(OS),WINNT) From 6abc0aeb1675e9d761eaeb1a6b4afd14d2e439ba Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 23 Dec 2013 12:22:09 -0500 Subject: [PATCH 89/89] fix #5225 --- src/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index a3ceaecd59120..cef208ce77f45 100644 --- a/src/gc.c +++ b/src/gc.c @@ -871,7 +871,7 @@ static void gc_mark(void) if (!gc_marked(v)) { jl_value_t *fin = finalizer_table.table[i+1]; if (gc_typeof(fin) == (jl_value_t*)jl_voidpointer_type) { - void *p = jl_unbox_voidpointer(fin); + void *p = ((void**)fin)[1]; if (p) ((void (*)(void*))p)(jl_data_ptr(v)); finalizer_table.table[i+1] = HT_NOTFOUND;