~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to .pc/use-sonames-with-dlopen.patch/base/bigint.jl

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-02-11 03:51:26 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130211035126-hap464pbhd97wjbl
Tags: 0.1~20130211.git86fbe98d-1
* New upstream snapshot.
* debian/control:
   + add git to Recommends (for Julia package manager)
   + remove dependencies on libglpk-dev (it moved to its own package)
   + add explicit dependency on libgmp10 (there is no more a wrapper)
* fix-clean-rules.patch: remove patch, applied upstream
* gsvddense_blasint.patch: new patch
* Refresh other patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
type BigInt <: Integer
 
2
    mpz::Vector{Int32}
 
3
    function BigInt() 
 
4
        z = Array(Int32, 5)
 
5
        ccall((:__gmpz_init,:libgmp), Void, (Ptr{Void},), z)
 
6
        b = new(z)
 
7
        finalizer(b, BigInt_clear)
 
8
        return b
 
9
    end
 
10
end
 
11
 
 
12
function BigInt(x::String)
 
13
    z = BigInt()
 
14
    err = ccall((:__gmpz_set_str, :libgmp), Int32, (Ptr{Void}, Ptr{Uint8}, Ptr{Int32}), z.mpz, bytestring(x), 0)
 
15
    if err != 0; error("Invalid input"); end
 
16
    return z
 
17
end
 
18
 
 
19
function BigInt(x::Int)
 
20
    z = BigInt()
 
21
    ccall((:__gmpz_set_si, :libgmp), Void, (Ptr{Void}, Int), z.mpz, x)
 
22
    return z
 
23
end
 
24
BigInt{T<:Signed}(x::T) = BigInt(int(x))
 
25
BigInt(x::Int128) = BigInt(string(x))
 
26
 
 
27
function BigInt(x::Uint)
 
28
    z = BigInt()
 
29
    ccall((:__gmpz_set_ui, :libgmp), Void,
 
30
        (Ptr{Void}, Uint), z.mpz, x)
 
31
    return z
 
32
end
 
33
BigInt{T<:Unsigned}(x::T) = BigInt(uint(x))
 
34
BigInt(x::Uint128) = BigInt(string(x))
 
35
 
 
36
convert(::Type{BigInt}, x::Int8) = BigInt(int(x))
 
37
convert(::Type{BigInt}, x::Int16) = BigInt(int(x))
 
38
convert(::Type{BigInt}, x::Int) = BigInt(x)
 
39
 
 
40
convert(::Type{BigInt}, x::Uint8) = BigInt(uint(x))
 
41
convert(::Type{BigInt}, x::Uint16) = BigInt(uint(x))
 
42
convert(::Type{BigInt}, x::Uint) = BigInt(x)
 
43
 
 
44
if WORD_SIZE == 64
 
45
    convert(::Type{BigInt}, x::Int32) = BigInt(int(x))
 
46
    convert(::Type{BigInt}, x::Uint32) = BigInt(uint(x))
 
47
else
 
48
    BigInt(l::Int64) = BigInt(string(l))
 
49
    BigInt(l::Uint64) = BigInt(string(l))
 
50
    convert(::Type{BigInt}, x::Int64) = BigInt(string(x))
 
51
    convert(::Type{BigInt}, x::Uint64) = BigInt(string(x))
 
52
end
 
53
 
 
54
convert(::Type{Int}, n::BigInt) =
 
55
    ccall((:__gmpz_get_si, :libgmp), Int, (Ptr{Void},), n.mpz)
 
56
 
 
57
convert(::Type{Uint}, n::BigInt) =
 
58
    ccall((:__gmpz_get_ui, :libgmp), Uint, (Ptr{Void},), n.mpz)
 
59
 
 
60
promote_rule(::Type{BigInt}, ::Type{Int8}) = BigInt
 
61
promote_rule(::Type{BigInt}, ::Type{Int16}) = BigInt
 
62
promote_rule(::Type{BigInt}, ::Type{Int32}) = BigInt
 
63
promote_rule(::Type{BigInt}, ::Type{Int64}) = BigInt
 
64
promote_rule(::Type{BigInt}, ::Type{Int128}) = BigInt
 
65
 
 
66
promote_rule(::Type{BigInt}, ::Type{Uint8}) = BigInt
 
67
promote_rule(::Type{BigInt}, ::Type{Uint16}) = BigInt
 
68
promote_rule(::Type{BigInt}, ::Type{Uint32}) = BigInt
 
69
promote_rule(::Type{BigInt}, ::Type{Uint64}) = BigInt
 
70
promote_rule(::Type{BigInt}, ::Type{Uint128}) = BigInt
 
71
 
 
72
# Binary ops
 
73
for (fJ, fC) in ((:+,:add), (:-,:sub), (:*,:mul), (:div,:fdiv_q), (:rem,:fdiv_r), (:gcd, :gcd))
 
74
    @eval begin 
 
75
        function ($fJ)(x::BigInt, y::BigInt)
 
76
            z = BigInt()
 
77
            ccall(($(string(:__gmpz_,fC)), :libgmp), Void, (Ptr{Void}, Ptr{Void}, Ptr{Void}), z.mpz, x.mpz, y.mpz)
 
78
            return z
 
79
        end
 
80
    end
 
81
end
 
82
 
 
83
function -(x::BigInt)
 
84
    z = BigInt()
 
85
    ccall((:__gmpz_neg, :libgmp), Void, (Ptr{Void}, Ptr{Void}), z.mpz, x.mpz)
 
86
    return z
 
87
end
 
88
 
 
89
function <<(x::BigInt, c::Uint)
 
90
    z = BigInt()
 
91
    ccall((:__gmpz_lshift, :libgmp), Void, (Ptr{Void}, Ptr{Void}, Uint), z.mpz, x.mpz, c)
 
92
    return z
 
93
end
 
94
<<(x::BigInt, c::Int32)   = c<0 ? throw(DomainError()) : x<<uint(c)
 
95
<<(x::BigInt, c::Integer) = c<0 ? throw(DomainError()) : x<<uint(c)
 
96
 
 
97
function >>(x::BigInt, c::Uint)
 
98
    z = BigInt()
 
99
    ccall((:__gmpz_rshift, :libgmp), Void, (Ptr{Void}, Ptr{Void}, Uint), z.mpz, x.mpz, c)
 
100
    return z
 
101
end
 
102
>>(x::BigInt, c::Int32)   = c<0 ? throw(DomainError()) : x>>uint(c)
 
103
>>(x::BigInt, c::Integer) = c<0 ? throw(DomainError()) : x>>uint(c)
 
104
 
 
105
function divmod(x::BigInt, y::BigInt)
 
106
    z1 = BigInt()
 
107
    z2 = BigInt()
 
108
    ccall((:__gmpz_divmod, :libgmp), Void, (Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}), z1, z2, x.mpz, y.mpz)
 
109
    BigInt(z1),BigInt(z2)
 
110
end
 
111
 
 
112
function cmp(x::BigInt, y::BigInt)
 
113
    ccall((:__gmpz_cmp, :libgmp), Int32, (Ptr{Void}, Ptr{Void}), x.mpz, y.mpz)
 
114
end
 
115
 
 
116
function sqrt(x::BigInt)
 
117
    z = BigInt()
 
118
    ccall((:__gmpz_sqrt, :libgmp), Void, (Ptr{Void}, Ptr{Void}), z.mpz, x.mpz)
 
119
    return z
 
120
end
 
121
 
 
122
function ^(x::BigInt, y::Uint)
 
123
    z = BigInt()
 
124
    ccall((:__gmpz_pow_ui, :libgmp), Void, (Ptr{Void}, Ptr{Void}, Uint), z.mpz, x.mpz, y)
 
125
    return z
 
126
end
 
127
 
 
128
function bigint_pow(x::BigInt, y::Integer)
 
129
    if y<0; throw(DomainError()); end
 
130
    if x== 1; return x; end
 
131
    if x==-1; return isodd(y) ? x : -x; end
 
132
    if y>typemax(Uint); throw(DomainError()); end
 
133
    return x^uint(y)
 
134
end
 
135
 
 
136
^(x::BigInt , y::BigInt ) = bigint_pow(x, y)
 
137
^(x::BigInt , y::Integer) = bigint_pow(x, y)
 
138
^(x::Integer, y::BigInt ) = bigint_pow(BigInt(x), y)
 
139
 
 
140
function gcdx(a::BigInt, b::BigInt)
 
141
    g = BigInt()
 
142
    s = BigInt()
 
143
    t = BigInt()
 
144
    ccall((:__gmpz_gcdext, :libgmp), Void,
 
145
        (Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}, Ptr{Void}),
 
146
        g, s, t, a.mpz, b.mpz)
 
147
    BigInt(g), BigInt(s), BigInt(t)
 
148
end
 
149
 
 
150
function factorial(bn::BigInt)
 
151
    if bn<0
 
152
        return BigInt(0)
 
153
    else
 
154
        n = uint(bn)
 
155
    end
 
156
    z = BigInt()
 
157
    ccall((:__gmpz_fac_ui, :libgmp), Void,
 
158
        (Ptr{Void}, Uint), z.mpz, n)
 
159
    return z
 
160
end
 
161
 
 
162
function binomial(n::BigInt, k::Uint)
 
163
    z = BigInt()
 
164
    ccall((:__gmpz_bin_ui, :libgmp), Void,
 
165
        (Ptr{Void}, Ptr{Void}, Uint), z.mpz, n.mpz, k)
 
166
    return z
 
167
end
 
168
binomial(n::BigInt, k::Integer) = k<0 ? throw(DomainError()) : binomial(n, uint(k))
 
169
 
 
170
==(x::BigInt, y::BigInt) = cmp(x,y) == 0
 
171
<=(x::BigInt, y::BigInt) = cmp(x,y) <= 0
 
172
>=(x::BigInt, y::BigInt) = cmp(x,y) >= 0
 
173
<(x::BigInt, y::BigInt) = cmp(x,y) < 0
 
174
>(x::BigInt, y::BigInt) = cmp(x,y) > 0
 
175
 
 
176
function string(x::BigInt)
 
177
    lng = ndigits(x) + 2
 
178
    z = Array(Uint8, lng)
 
179
    lng = ccall((:__gmp_snprintf,:libgmp), Int32, (Ptr{Uint8}, Int32, Ptr{Uint8}, Ptr{Void}), z, lng, "%Zd", x.mpz)
 
180
    return bytestring(convert(Ptr{Uint8}, z[1:lng]))
 
181
end
 
182
 
 
183
function show(io::IO, x::BigInt)
 
184
    print(io, string(x))
 
185
end
 
186
 
 
187
function BigInt_clear(x::BigInt)
 
188
    ccall((:__gmpz_clear, :libgmp), Void, (Ptr{Void},), x.mpz)
 
189
end
 
190
 
 
191
ndigits(x::BigInt) = ccall((:__gmpz_sizeinbase,:libgmp), Int32, (Ptr{Void}, Int32), x.mpz, 10)