Skip to content

Commit 0eaf8c8

Browse files
authored
Merge pull request #33 from JuliaMath/ludvigak-complex
Fix transcdendentals with complex args
2 parents 4ae6473 + c8b8b6c commit 0eaf8c8

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

src/Quadmath.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Base: (*), +, -, /, <, <=, ==, ^, convert,
88
significand_mask, exponent, significand,
99
promote_rule, widen,
1010
string, print, show, parse,
11-
acos, acosh, asin, asinh, atan, atanh, cosh, cos,
11+
acos, acosh, asin, asinh, atan, atanh, cosh, cos, sincos,
1212
exp, expm1, log, log2, log10, log1p, sin, sinh, sqrt,
1313
tan, tanh,
1414
ceil, floor, trunc, round, fma,
@@ -41,7 +41,7 @@ macro ccall(expr)
4141

4242
expr_call = expr.args[1]
4343
@assert expr_call isa Expr && expr_call.head == :call
44-
44+
4545
expr_fname = expr_call.args[1]
4646

4747
if expr_fname isa Symbol
@@ -51,9 +51,9 @@ macro ccall(expr)
5151
end
5252

5353
expr_args = expr_call.args[2:end]
54-
55-
@assert all(ex isa Expr && ex.head == :(::) for ex in expr_args)
56-
54+
55+
@assert all(ex isa Expr && ex.head == :(::) for ex in expr_args)
56+
5757
arg_names = [ex.args[1] for ex in expr_args]
5858
arg_types = [ex.args[2] for ex in expr_args]
5959

@@ -65,7 +65,7 @@ macro ccall(expr)
6565
r = Ref{Cfloat128}()
6666
ccall($fname, Cvoid, (Ref{Cfloat128}, $(esc.(arg_types)...),), r, $(esc.(arg_names)...))
6767
r[]
68-
end
68+
end
6969
else
7070
:(ccall($fname, $(esc(ret_type)), ($(esc.(arg_types)...),), $(esc.(arg_names)...)))
7171
end
@@ -345,11 +345,15 @@ hypot(x::Float128, y::Float128) =
345345
Float128(@ccall(libquadmath.hypotq(x::Cfloat128, y::Cfloat128)::Cfloat128))
346346
atan(x::Float128, y::Float128) =
347347
Float128(@ccall(libquadmath.atan2q(x::Cfloat128, y::Cfloat128)::Cfloat128))
348+
sincos(x::Float128) = (sin(x), cos(x))
348349

349350
## misc
350-
fma(x::Float128, y::Float128, z::Float128) =
351-
Float128(@ccall(libquadmath.fmaq(x::Cfloat128, y::Cfloat128, z::Cfloat128)::Cfloat128))
352-
351+
@static if !Sys.iswindows()
352+
# disable fma on Windows until rounding mode issue fixed
353+
# https://github.com/JuliaMath/Quadmath.jl/issues/31
354+
fma(x::Float128, y::Float128, z::Float128) =
355+
Float128(@ccall(libquadmath.fmaq(x::Cfloat128, y::Cfloat128, z::Cfloat128)::Cfloat128))
356+
end
353357

354358
isnan(x::Float128) = 0 != @ccall(libquadmath.isnanq(x::Cfloat128)::Cint)
355359
isinf(x::Float128) = 0 != @ccall(libquadmath.isinfq(x::Cfloat128)::Cint)
@@ -366,8 +370,8 @@ precision(::Type{Float128}) = 113
366370
eps(::Type{Float128}) = reinterpret(Float128, 0x3f8f_0000_0000_0000_0000_0000_0000_0000)
367371
floatmin(::Type{Float128}) = reinterpret(Float128, 0x0001_0000_0000_0000_0000_0000_0000_0000)
368372
floatmax(::Type{Float128}) = reinterpret(Float128, 0x7ffe_ffff_ffff_ffff_ffff_ffff_ffff_ffff)
369-
370373
maxintfloat(::Type{Float128}) = Float128(0x0002_0000_0000_0000_0000_0000_0000_0000)
374+
371375
"""
372376
Inf128
373377

test/runtests.jl

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end
5555
x = parse(Float128, "100.0")
5656
y = parse(Float128, "25.0")
5757
@test Float64(x+y) == Float64(BigInt(x) + BigInt(y))
58-
@test x+y == Float128(BigInt(x) + BigInt(y))
58+
@test x+y == Float128(BigInt(x) + BigInt(y))
5959
end
6060
end
6161

@@ -86,7 +86,7 @@ end
8686
fpart, ipart = modf(y)
8787
@test y == ipart + fpart
8888
@test signbit(fpart) == signbit(ipart) == true
89-
89+
9090
z = x^3
9191
fpart, ipart = modf(x) .+ modf(y)
9292
@test x+y == ipart+fpart
@@ -113,20 +113,28 @@ end
113113

114114
@testset "transcendental etc. calls" begin
115115
# at least enough to cover all the wrapping code
116-
x = sqrt(Float128(2.0))
117-
xd = Float64(x)
118-
@test (x^Float128(4.0)) Float128(4.0)
119-
@test exp(x) exp(xd)
120-
@test abs(x) == x
121-
@test hypot(Float128(3),Float128(4)) == Float128(5)
122-
@test atan(x,x) Float128(pi) / 4
123-
h = floatmax(Float128)
124-
@test isinf(h+h)
125-
@test fma(x,x,Float128(-1.0)) Float128(1)
126-
if Sys.iswindows()
127-
@test_broken isinf(h+h)
128-
else
129-
@test isinf(h+h)
116+
@testset "real" begin
117+
x = sqrt(Float128(2.0))
118+
xd = Float64(x)
119+
@test (x^Float128(4.0)) Float128(4.0)
120+
@test exp(x) exp(xd)
121+
@test abs(x) == x
122+
@test hypot(Float128(3),Float128(4)) == Float128(5)
123+
@test atan(x,x) Float128(pi) / 4
124+
if !Sys.iswindows()
125+
@test fma(x,x,Float128(-1.0)) Float128(1)
126+
end
127+
end
128+
@testset "complex" begin
129+
x = sqrt(ComplexF128(1.0 + 1.0im))
130+
xd = ComplexF64(x)
131+
@test x^x xd^xd
132+
@test exp(x) exp(xd)
133+
@test abs(x) abs(xd)
134+
@test sin(x) sin(xd)
135+
@test cos(x) cos(xd)
136+
@test tan(x) tan(xd)
137+
@test log(x) log(xd)
130138
end
131139
end
132140

0 commit comments

Comments
 (0)