Skip to content

cleanups #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 10 additions & 63 deletions src/Quadmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,39 +82,20 @@ end
# and passed on the xmm registers, matching the x86_64 ABI for __float128.
const Cfloat128 = NTuple{2,VecElement{Float64}}

struct Float128 <: AbstractFloat
data::Cfloat128
function Float128(data::Cfloat128)
new(data)
end
end
primitive type Float128 <: AbstractFloat 128 end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a breaking change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe bump the version number?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. If we're going to make a breaking release, might as well take the opportunity to do 1.0.0 now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually breaking? I would be very surprised if anyone was using the layout of this type. That said, no objection to making a 1.0 tag...

Float128(data::Cfloat128) = reinterpret(Float128, data)

convert(::Type{Float128}, x::Number) = Float128(x)

const ComplexF128 = Complex{Float128}

Base.cconvert(::Type{Cfloat128}, x::Float128) = x.data
Base.cconvert(::Type{Ref{Cfloat128}}, x::Float128) = Ref{Cfloat128}(x.data)

Base.cconvert(::Type{Cfloat128}, x::Float128) = reinterpret(Cfloat128, x)
Base.cconvert(::Type{Ref{Cfloat128}}, x::Float128) = Ref(Cfloat128(x))

# reinterpret
function reinterpret(::Type{UInt128}, x::Float128)
hi = reinterpret(UInt64, x.data[2].value)
lo = reinterpret(UInt64, x.data[1].value)
UInt128(hi) << 64 | lo
end
function reinterpret(::Type{Float128}, x::UInt128)
fhi = reinterpret(Float64, (x >> 64) % UInt64)
flo = reinterpret(Float64, x % UInt64)
Float128((VecElement(flo), VecElement(fhi)))
end
reinterpret(::Type{Unsigned}, x::Float128) = reinterpret(UInt128, x)
reinterpret(::Type{Signed}, x::Float128) = reinterpret(Int128, x)

reinterpret(::Type{Int128}, x::Float128) =
reinterpret(Int128, reinterpret(UInt128, x))
reinterpret(::Type{Float128}, x::Int128) =
reinterpret(Float128, reinterpret(UInt128, x))

sign_mask(::Type{Float128}) = 0x8000_0000_0000_0000_0000_0000_0000_0000
exponent_mask(::Type{Float128}) = 0x7fff_0000_0000_0000_0000_0000_0000_0000
exponent_one(::Type{Float128}) = 0x3fff_0000_0000_0000_0000_0000_0000_0000
Expand Down Expand Up @@ -481,20 +462,10 @@ end

function BigFloat(x::Float128; precision=precision(BigFloat))
if !isfinite(x) || iszero(x)
@static if VERSION < v"1.1"
return BigFloat(Float64(x), precision)
else
return BigFloat(Float64(x), precision=precision)
end
return BigFloat(Float64(x), precision=precision)
end

@static if VERSION < v"1.1"
b = setprecision(BigFloat, max(precision,113)) do
BigFloat()
end
else
b = BigFloat(precision=max(precision,113))
end
b = BigFloat(precision=max(precision,113))

y, k = frexp(x)
b.exp = Clong(k)
Expand All @@ -514,16 +485,7 @@ function BigFloat(x::Float128; precision=precision(BigFloat))
end

if precision < 113
@static if VERSION < v"1.1"
b2 = setprecision(BigFloat, precision) do
BigFloat()
end
ccall((:mpfr_set, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Int32),
b2, b, MPFR.ROUNDING_MODE[])
return b2
else
return BigFloat(b, precision=precision)
end
return BigFloat(b, precision=precision)
else
return b
end
Expand All @@ -545,16 +507,7 @@ function Float128(x::BigFloat)
z = reinterpret(Float128, UInt128(0))
end

@static if VERSION < v"1.1"
y = setprecision(BigFloat, prec) do
BigFloat()
end
ccall((:mpfr_set, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Int32),
y, x, MPFR.ROUNDING_MODE[])
else
y = BigFloat(x, precision=prec)
end

y = BigFloat(x, precision=prec)
u = zero(UInt128)
i = cld(prec, sizeof(MPFR.Limb)*8)
j = 113
Expand All @@ -574,13 +527,7 @@ function BigInt(x::Float128)
BigInt(BigFloat(x, precision=precision(Float128)))
end
function Float128(x::BigInt)
@static if VERSION < v"1.1"
y = setprecision(BigFloat, precision(Float128)) do
BigFloat(x)
end
else
y = BigFloat(x, precision=precision(Float128))
end
y = BigFloat(x, precision=precision(Float128))
Float128(y)
end

Expand Down
Loading