Skip to content

Commit

Permalink
test library call wrappers (and correct typo)
Browse files Browse the repository at this point in the history
  • Loading branch information
RalphAS committed Mar 9, 2019
1 parent 49aae49 commit d3e9b69
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Quadmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ if _WIN_PTR_ABI
(Ptr{Cfloat128}, Ref{Cfloat128}, Ref{Cfloat128}), r, x, y)
Float128(r[])
end
elseif Sys.iswindows()
function (^)(x::Float128, y::Float128)
r = Ref{Cfloat128}()
p = PadPtr(r)
ccall((:powq,quadoplib), Cvoid, (PF128, Cfloat128, Cfloat128), p, x, y)
Float128(r[])
end
else
(^)(x::Float128, y::Float128) =
Float128(ccall((:powq, libquadmath), Cfloat128,
Expand Down Expand Up @@ -391,15 +398,15 @@ end
for f in (:copysign, :hypot, )
if _WIN_PTR_ABI
@eval function $f(x::Float128, y::Float128)
r = Ref{Cloat128}()
r = Ref{Cfloat128}()
ccall(($(string(f,:q)), libquadmath), Cvoid,
(Ptr{Cfloat128}, Ref{Cfloat128}, Ref{Cfloat128}),
r, x, y)
Float128(r[])
end
elseif Sys.iswindows()
@eval function $f(x::Float128, y::Float128)
r = Ref{Cloat128}()
r = Ref{Cfloat128}()
p = PadPtr(r)
ccall(($(string(f,:q)), libquadmath), Cvoid,
(PF128, Cfloat128, Cfloat128),
Expand All @@ -417,14 +424,14 @@ flipsign(x::Float128, y::Float128) = signbit(y) ? -x : x

if _WIN_PTR_ABI
function atan(x::Float128, y::Float128)
r = Ref{Cloat128}()
r = Ref{Cfloat128}()
ccall((:atan2q, libquadmath), Cvoid, (Ptr{Cfloat128}, Ref{Cfloat128}, Ref{Cfloat128}), r, x, y)
Float128(r[])
end

## misc
function fma(x::Float128, y::Float128, z::Float128)
r = Ref{Cloat128}()
r = Ref{Cfloat128}()
ccall((:fmaq,libquadmath), Cvoid, (Ptr{Cfloat128}, Ref{Cfloat128}, Ref{Cfloat128}, Ref{Cfloat128}), r, x, y, z)
Float128(r[])
end
Expand All @@ -438,15 +445,15 @@ if _WIN_PTR_ABI
else
if Sys.iswindows()
function atan(x::Float128, y::Float128)
r = Ref{Cloat128}()
r = Ref{Cfloat128}()
p = PadPtr(r)
ccall((:atan2q, libquadmath), Cvoid,
(PF128, Cfloat128, Cfloat128), p, x, y)
Float128(r[])
end

function fma(x::Float128, y::Float128, z::Float128)
r = Ref{Cloat128}()
r = Ref{Cfloat128}()
p = PadPtr(r)
ccall((:fmaq,libquadmath), Cvoid,
(PF128, Cfloat128, Cfloat128, Cfloat128), p, x, y, z)
Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,19 @@ end
fpart, ipart = modf(x) .+ modf(y)
@test x+y == ipart+fpart
end

@testset "transcendental etc. calls" begin
# at least enough to cover all the wrapping code
x = sqrt(Float128(2.0))
xd = Float64(x)
@test (x^Float128(4.0)) Float128(4.0)
@test exp(x) exp(xd)
@test abs(x) == x
@test hypot(Float128(3),Float128(4)) == Float128(5)
@test atan(x,x) Float128(pi) / 4
@test fma(x,x,Float128(-1.0)) Float128(1)
end

if !Sys.iswindows() || (Sys.WORD_SIZE == 64)
include("specfun.jl")
end
15 changes: 15 additions & 0 deletions test/specfun.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using SpecialFunctions

@testset "special functions" begin
# The intention here is not to check the accuracy of the libraries,
# rather the sanity of library calls:
piq = Float128(pi)
halfq = Float128(0.5)
@test gamma(halfq) sqrt(piq)
for func in (erf, erfc, besselj0, besselj1, bessely0, bessely1, lgamma)
@test func(halfq) func(0.5)
end
for func in (bessely, besselj)
@test func(3,halfq) func(3,0.5)
end
end

0 comments on commit d3e9b69

Please sign in to comment.