Skip to content

Commit

Permalink
fix convert(Int64,::BigFloat) bug on 32-bit systems (closes JuliaLang…
Browse files Browse the repository at this point in the history
  • Loading branch information
nolta committed Sep 12, 2014
1 parent 9176b3d commit ddc2244
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ end
typealias Cptrdiff_t Int
typealias Csize_t Uint
typealias Cssize_t Int
typealias Cintmax_t Int64
typealias Cuintmax_t Uint64
typealias Clonglong Int64
typealias Culonglong Uint64
typealias Cfloat Float32
Expand Down
2 changes: 2 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export
Cdouble,
Cfloat,
Cint,
Cintmax_t,
Clong,
Clonglong,
Coff_t,
Expand All @@ -128,6 +129,7 @@ export
Cssize_t,
Cuchar,
Cuint,
Cuintmax_t,
Culong,
Culonglong,
Cushort,
Expand Down
8 changes: 4 additions & 4 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ for to in (Int8, Int16, Int32, Int64)
@eval begin
function convert(::Type{$to}, x::BigFloat)
(isinteger(x) && (typemin($to) <= x <= typemax($to))) || throw(InexactError())
convert($to, ccall((:mpfr_get_si,:libmpfr),
Clong, (Ptr{BigFloat}, Int32), &x, 0))
convert($to, ccall((:__gmpfr_mpfr_get_sj,:libmpfr),
Cintmax_t, (Ptr{BigFloat}, Int32), &x, 0))
end
end
end
Expand All @@ -103,8 +103,8 @@ for to in (Uint8, Uint16, Uint32, Uint64)
@eval begin
function convert(::Type{$to}, x::BigFloat)
(isinteger(x) && (typemin($to) <= x <= typemax($to))) || throw(InexactError())
convert($to, ccall((:mpfr_get_ui,:libmpfr),
Culong, (Ptr{BigFloat}, Int32), &x, 0))
convert($to, ccall((:__gmpfr_mpfr_get_uj,:libmpfr),
Cuintmax_t, (Ptr{BigFloat}, Int32), &x, 0))
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -797,3 +797,6 @@ i3 = itrunc(f)
err(z, x) = abs(z - x) / abs(x)
@test 1e-60 > err(eta(BigFloat("1.005")), BigFloat("0.693945708117842473436705502427198307157819636785324430166786"))
@test 1e-60 > err(exp(eta(big(1.0))), 2.0)

# issue 8318
@test convert(Int64,big(500_000_000_000_000.)) == 500_000_000_000_000

0 comments on commit ddc2244

Please sign in to comment.