Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 42fd6b1

Browse files
committedDec 3, 2014
small fixup for rand(::BigInt) and update docs
Now the runtime version of GMP is checked against the compile time version, as suggested by @JeffBezanson. He also noted that the limbs field of RangeGeneratorBigInt was not specific enough.
1 parent 1673768 commit 42fd6b1

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed
 

‎base/gmp.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ else
1818
end
1919
typealias CdoubleMax Union(Float16, Float32, Float64)
2020

21-
const GMP_VERSION = VersionNumber(bytestring(unsafe_load(cglobal((:__gmp_version, :libgmp), Ptr{Cchar}))))
22-
const GMP_BITS_PER_LIMB = Int(unsafe_load(cglobal((:__gmp_bits_per_limb, :libgmp), Cint)))
21+
gmp_version() = VersionNumber(bytestring(unsafe_load(cglobal((:__gmp_version, :libgmp), Ptr{Cchar}))))
22+
gmp_bits_per_limb() = Int(unsafe_load(cglobal((:__gmp_bits_per_limb, :libgmp), Cint)))
23+
24+
const GMP_VERSION = gmp_version()
25+
const GMP_BITS_PER_LIMB = gmp_bits_per_limb()
2326

2427
# GMP's mp_limb_t is by default a typedef of `unsigned long`, but can also be configured to be either
2528
# `unsigned int` or `unsigned long long int`. The correct unsigned type is here named Limb, and must
@@ -49,6 +52,11 @@ _gmp_clear_func = C_NULL
4952
_mpfr_clear_func = C_NULL
5053

5154
function __init__()
55+
if gmp_version() != GMP_VERSION || gmp_bits_per_limb() != GMP_BITS_PER_LIMB
56+
error(string("the dynamically loaded GMP library (version $(gmp_version()) with __gmp_bits_per_limb == $(gmp_bits_per_limb()))\n",
57+
"does not correspond to the compile time version (version $GMP_VERSION with __gmp_bits_per_limb == $GMP_BITS_PER_LIMB)"))
Has conversations. Original line has conversations.
58+
end
59+
5260
global _gmp_clear_func = cglobal((:__gmpz_clear, :libgmp))
5361
global _mpfr_clear_func = cglobal((:mpfr_clear, :libmpfr))
5462
ccall((:__gmp_set_memory_functions, :libgmp), Void,

‎base/random.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ else
399399
immutable RangeGeneratorBigInt <: RangeGenerator
400400
a::BigInt # first
401401
m::BigInt # range length - 1
402-
limbs::Array{Limb} # buffer to be copied into generated BigInt's
402+
limbs::Vector{Limb} # buffer to be copied into generated BigInt's
403403
mask::Limb # applied to the highest limb
404404

405405
RangeGeneratorBigInt(a, m, nlimbs, mask) = new(a, m, Array(Limb, nlimbs), mask)

‎doc/stdlib/base.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -4083,7 +4083,7 @@ Random number generation in Julia uses the `Mersenne Twister library <http://www
40834083

40844084
Most functions related to random generation accept an optional ``AbstractRNG`` as the first argument, ``rng`` , which defaults to the global one if not provided. Morever, some of them accept optionally dimension specifications ``dims...`` (which can be given as a tuple) to generate arrays of random values.
40854085

4086-
A ``MersenneTwister`` RNG can generate random numbers of the following types: ``Float16, Float32, Float64, Bool, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128`` (or complex numbers or arrays of those types). Random floating point numbers are generated uniformly in [0,1).
4086+
A ``MersenneTwister`` RNG can generate random numbers of the following types: ``Float16``, ``Float32``, ``Float64``, ``Bool``, ``Int8``, ``UInt8``, ``Int16``, ``UInt16``, ``Int32``, ``UInt32``, ``Int64``, ``UInt64``, ``Int128``, ``UInt128``, ``BigIng`` (or complex numbers of those types). Random floating point numbers are generated uniformly in [0,1). As ``BigInt`` represents unbounded integers, the interval must be specified (e.g. ``rand(big(1:6))``).
Has conversations. Original line has conversations.
40874087

40884088
.. function:: srand([rng], [seed])
40894089

@@ -4099,7 +4099,7 @@ A ``MersenneTwister`` RNG can generate random numbers of the following types: ``
40994099

41004100
* an indexable collection (for example ``1:n`` or ``['x','y','z']``), or
41014101

4102-
* a type: the set of values to pick from is then equivalent to ``typemin(S):typemax(S)`` for integers, and to [0,1) for floating point numbers;
4102+
* a type: the set of values to pick from is then equivalent to ``typemin(S):typemax(S)`` for integers (this is not applicable to ``BigInt``), and to [0,1) for floating point numbers;
41034103

41044104
``S`` defaults to ``Float64``.
41054105

3 commit comments

Comments
 (3)

ViralBShah commented on Dec 3, 2014

@ViralBShah
Member

Will you be creating a PR for this?

rfourquet commented on Dec 3, 2014

@rfourquet
MemberAuthor

I didn't intend to... it's such a small change, so I linked to this branch in #9122, as a follow-up. Should I create a PR?

ViralBShah commented on Dec 3, 2014

@ViralBShah
Member

No, it isn't necessary - I realized it was on the same branch, and was just wondering how you were planning to incorporate into master.

Please sign in to comment.