Skip to content

Commit 1d55d1d

Browse files
authored
update for 0.7/1.0 (#6)
1 parent 4d17c2f commit 1d55d1d

File tree

6 files changed

+113
-94
lines changed

6 files changed

+113
-94
lines changed

.appveyor.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
environment:
2+
matrix:
3+
- julia_version: 0.7
4+
- julia_version: 1
5+
- julia_version: nightly
6+
7+
platform:
8+
- x86 # 32-bit
9+
- x64 # 64-bit
10+
11+
# # Uncomment the following lines to allow failures on nightly julia
12+
# # (tests will run but not make your overall status red)
13+
# matrix:
14+
# allow_failures:
15+
# - julia_version: nightly
16+
17+
branches:
18+
only:
19+
- master
20+
- /release-.*/
21+
22+
notifications:
23+
- provider: Email
24+
on_build_success: false
25+
on_build_failure: false
26+
on_build_status_changed: false
27+
28+
install:
29+
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
30+
31+
build_script:
32+
- echo "%JL_BUILD_SCRIPT%"
33+
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
34+
35+
test_script:
36+
- echo "%JL_TEST_SCRIPT%"
37+
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.5
7+
- 0.7
8+
- 1.0
89
- nightly
910
notifications:
1011
email: false

REQUIRE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
julia 0.5
1+
julia 0.7
2+
Requires

appveyor.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Quadmath.jl

Lines changed: 71 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
__precompile__()
22
module Quadmath
3+
using Requires
34

4-
export Float128, Complex256
5+
export Float128, ComplexF128
56

67
import Base: (*), +, -, /, <, <=, ==, ^, convert,
78
reinterpret, sign_mask, exponent_mask, exponent_one, exponent_half,
89
significand_mask,
910
promote_rule, widen,
10-
string, print, show, showcompact, parse,
11+
string, print, show, parse,
1112
acos, acosh, asin, asinh, atan, atanh, cosh, cos,
12-
erf, erfc, exp, expm1, log, log2, log10, log1p, sin, sinh, sqrt,
13+
exp, expm1, log, log2, log10, log1p, sin, sinh, sqrt,
1314
tan, tanh,
14-
besselj, besselj0, besselj1, bessely, bessely0, bessely1,
15-
ceil, floor, trunc, round, fma,
16-
atan2, copysign, max, min, hypot,
17-
gamma, lgamma,
15+
ceil, floor, trunc, round, fma,
16+
copysign, max, min, hypot,
1817
abs, imag, real, conj, angle, cis,
19-
eps, realmin, realmax, isinf, isnan, isfinite
18+
eps, isinf, isnan, isfinite,
19+
Int32,Int64,Float64
2020

21-
if is_apple()
21+
if Sys.isapple()
2222
const quadoplib = "libquadmath.0"
2323
const libquadmath = "libquadmath.0"
24-
elseif is_unix()
25-
const quadoplib = "libgcc_s"
24+
elseif Sys.isunix()
25+
const quadoplib = "libgcc_s.so.1"
2626
const libquadmath = "libquadmath.so.0"
27-
elseif is_windows()
27+
elseif Sys.iswindows()
2828
const quadoplib = "libgcc_s_seh-1.dll"
2929
const libquadmath = "libquadmath-0.dll"
3030
end
3131

32-
33-
@static if is_unix()
32+
@static if Sys.isunix()
3433
# we use this slightly cumbersome definition to ensure that the value is passed
3534
# on the xmm registers, matching the x86_64 ABI for __float128.
36-
typealias Cfloat128 NTuple{2,VecElement{Float64}}
35+
const Cfloat128 = NTuple{2,VecElement{Float64}}
3736

38-
immutable Float128 <: AbstractFloat
37+
struct Float128 <: AbstractFloat
3938
data::Cfloat128
4039
end
41-
Float128(x::Number) = convert(Float128, x)
40+
convert(::Type{Float128}, x::Number) = Float128(x)
4241

43-
typealias Complex256 Complex{Float128}
42+
const ComplexF128 = Complex{Float128}
4443

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

@@ -62,12 +61,33 @@ end
6261
reinterpret(Int128, reinterpret(UInt128, x))
6362
reinterpret(::Type{Float128}, x::Int128) =
6463
reinterpret(Float128, reinterpret(UInt128, x))
65-
66-
elseif is_windows()
67-
bitstype 128 Float128
68-
typealias Cfloat128 Float128
64+
65+
elseif Sys.iswindows()
66+
primitive type Float128 <: AbstractFloat 128
67+
end
68+
const Cfloat128 = Float128
69+
end
70+
71+
function __init__()
72+
@require SpecialFunctions="276daf66-3868-5448-9aa4-cd146d93841b" begin
73+
using SpecialFunctions
74+
75+
SpecialFunctions.erf(x::Float128) = Float128(ccall((:erfq, libquadmath), Cfloat128, (Cfloat128, ), x))
76+
SpecialFunctions.erfc(x::Float128) = Float128(ccall((:erfcq, libquadmath), Cfloat128, (Cfloat128, ), x))
77+
78+
SpecialFunctions.besselj0(x::Float128) = Float128(ccall((:j0q, libquadmath), Cfloat128, (Cfloat128, ), x))
79+
SpecialFunctions.besselj1(x::Float128) = Float128(ccall((:j1q, libquadmath), Cfloat128, (Cfloat128, ), x))
80+
SpecialFunctions.bessely0(x::Float128) = Float128(ccall((:y0q, libquadmath), Cfloat128, (Cfloat128, ), x))
81+
SpecialFunctions.bessely1(x::Float128) = Float128(ccall((:y1q, libquadmath), Cfloat128, (Cfloat128, ), x))
82+
SpecialFunctions.besselj(n::Cint, x::Float128) = Float128(ccall((:jnq, libquadmath), Cfloat128, (Cint, Cfloat128), n, x))
83+
SpecialFunctions.bessely(n::Cint, x::Float128) = Float128(ccall((:ynq, libquadmath), Cfloat128, (Cint, Cfloat128), n, x))
84+
85+
SpecialFunctions.gamma(x::Float128) = Float128(ccall((:tgammaq, libquadmath), Cfloat128, (Cfloat128, ), x))
86+
SpecialFunctions.lgamma(x::Float128) = Float128(ccall((:lgammaq, libquadmath), Cfloat128, (Cfloat128, ), x))
87+
end
6988
end
7089

90+
7191
sign_mask(::Type{Float128}) = 0x8000_0000_0000_0000_0000_0000_0000_0000
7292
exponent_mask(::Type{Float128}) = 0x7fff_0000_0000_0000_0000_0000_0000_0000
7393
exponent_one(::Type{Float128}) = 0x3fff_0000_0000_0000_0000_0000_0000_0000
@@ -77,26 +97,28 @@ significand_mask(::Type{Float128}) = 0x0000_ffff_ffff_ffff_ffff_ffff_ffff_ffff
7797
fpinttype(::Type{Float128}) = UInt128
7898

7999
# conversion
100+
Float128(x::Float128) = x
80101

81102
## Float64
82-
convert(::Type{Float128}, x::Float64) =
103+
Float128(x::Float64) =
83104
Float128(ccall((:__extenddftf2, quadoplib), Cfloat128, (Cdouble,), x))
84-
convert(::Type{Float64}, x::Float128) =
105+
Float64(x::Float128) =
85106
ccall((:__trunctfdf2, quadoplib), Cdouble, (Cfloat128,), x)
86107

87-
convert(::Type{Int32}, x::Float128) =
108+
Int32(x::Float128) =
88109
ccall((:__fixtfsi, quadoplib), Int32, (Cfloat128,), x)
89-
convert(::Type{Float128}, x::Int32) =
110+
Float128(x::Int32) =
90111
Float128(ccall((:__floatsitf, quadoplib), Cfloat128, (Int32,), x))
91112

92-
convert(::Type{Float128}, x::UInt32) =
113+
Float128(x::UInt32) =
93114
Float128(ccall((:__floatunsitf, quadoplib), Cfloat128, (UInt32,), x))
94115

95-
convert(::Type{Int64}, x::Float128) =
116+
Int64(x::Float128) =
96117
ccall((:__fixtfdi, quadoplib), Int64, (Cfloat128,), x)
97-
convert(::Type{Float128}, x::Int64) =
118+
Float128(x::Int64) =
98119
Float128(ccall((:__floatditf, quadoplib), Cfloat128, (Int64,), x))
99120

121+
Float128(x::Rational{T}) where T = Float128(numerator(x))/Float128(denominator(x))
100122

101123
# comparison
102124

@@ -121,37 +143,37 @@ convert(::Type{Float128}, x::Int64) =
121143
Float128(ccall((:__divtf3,quadoplib), Cfloat128, (Cfloat128,Cfloat128), x, y))
122144
(-)(x::Float128) =
123145
Float128(ccall((:__negtf2,quadoplib), Cfloat128, (Cfloat128,), x))
124-
146+
(^)(x::Float128, y::Float128) =
147+
Float128(ccall((:powq, libquadmath), Cfloat128, (Cfloat128,Cfloat128), x, y))
125148
# math
126149

127150
## one argument
128151
for f in (:acos, :acosh, :asin, :asinh, :atan, :atanh, :cosh, :cos,
129152
:erf, :erfc, :exp, :expm1, :log, :log2, :log10, :log1p,
130-
:sin, :sinh, :sqrt, :tan, :tanh,
131-
:ceil, :floor, :trunc, :lgamma, )
153+
:sin, :sinh, :sqrt, :tan, :tanh,
154+
:ceil, :floor, :trunc, )
132155
@eval function $f(x::Float128)
133156
Float128(ccall(($(string(f,:q)), libquadmath), Cfloat128, (Cfloat128, ), x))
134157
end
135158
end
136159
for (f,fc) in (:abs => :fabs,
137-
:round => :rint,
138-
:gamma => :tgamma,
139-
:besselj0 => :j0,
140-
:besselj1 => :j1,
141-
:bessely0 => :y0,
142-
:bessely1 => :y1,)
160+
:round => :rint,)
143161
@eval function $f(x::Float128)
144162
Float128(ccall(($(string(fc,:q)), libquadmath), Cfloat128, (Cfloat128, ), x))
145163
end
146164
end
147165

148166
## two argument
149-
for f in (:atan2, :copysign, :hypot, )
167+
for f in (:copysign, :hypot, )
150168
@eval function $f(x::Float128, y::Float128)
151169
Float128(ccall(($(string(f,:q)), libquadmath), Cfloat128, (Cfloat128, Cfloat128), x, y))
152170
end
153171
end
154172

173+
function atan(x::Float128, y::Float128)
174+
Float128(ccall((:atan2q, libquadmath), Cfloat128, (Cfloat128, Cfloat128), x, y))
175+
end
176+
155177
## misc
156178
fma(x::Float128, y::Float128, z::Float128) =
157179
Float128(ccall((:fmaq,libquadmath), Cfloat128, (Cfloat128, Cfloat128, Cfloat128), x, y, z))
@@ -163,12 +185,11 @@ isinf(x::Float128) =
163185
isfinite(x::Float128) =
164186
0 != ccall((:finiteq,libquadmath), Cint, (Cfloat128, ), x)
165187

166-
besselj(n::Cint, x::Float128) =
167-
Float128(ccall((:jnq, libquadmath), Cfloat128, (Cint, Cfloat128), n, x))
168-
bessely(n::Cint, x::Float128) =
169-
Float128(ccall((:ynq, libquadmath), Cfloat128, (Cint, Cfloat128), n, x))
170-
171-
188+
eps(::Type{Float128}) = reinterpret(Float128, 0x3f8f0000000000000000000000000000)
189+
realmin(::Type{Float128}) = reinterpret(Float128, 0x00010000000000000000000000000000)
190+
realmax(::Type{Float128}) = reinterpret(Float128, 0x7ffeffffffffffffffffffffffffffff)
191+
Float128(::Irrational{:π}) = reinterpret(Float128, 0x4000921fb54442d18469898cc51701b8)
192+
Float128(::Irrational{:e}) = reinterpret(Float128, 0x40005bf0a8b1457695355fb8ac404e7a)
172193

173194

174195
ldexp(x::Float128, n::Cint) =
@@ -181,12 +202,11 @@ function frexp(x::Float128)
181202
Float128(ccall((:frexpq, libquadmath), Cfloat128, (Cfloat128, Ptr{Cint}), x, r))
182203
return x, Int(r[])
183204
end
184-
185-
186-
187205

206+
promote_rule(::Type{Float128}, ::Type{Float16}) = Float128
188207
promote_rule(::Type{Float128}, ::Type{Float32}) = Float128
189208
promote_rule(::Type{Float128}, ::Type{Float64}) = Float128
209+
promote_rule(::Type{Float128}, ::Type{<:Integer}) = Float128
190210

191211
#widen(::Type{Float64}) = Float128
192212
widen(::Type{Float128}) = BigFloat
@@ -197,14 +217,13 @@ function parse(::Type{Float128}, s::AbstractString)
197217
end
198218

199219
function string(x::Float128)
200-
lng = 64
201-
buf = Array(UInt8, lng + 1)
220+
lng = 64
221+
buf = Array{UInt8}(undef, lng + 1)
202222
lng = ccall((:quadmath_snprintf,libquadmath), Cint, (Ptr{UInt8}, Csize_t, Ptr{UInt8}, Cfloat128...), buf, lng + 1, "%.35Qe", x)
203-
return unsafe_string(pointer(buf), lng)
223+
return String(resize!(buf, lng))
204224
end
205225

206226
print(io::IO, b::Float128) = print(io, string(b))
207227
show(io::IO, b::Float128) = print(io, string(b))
208-
showcompact(io::IO, b::Float128) = print(io, string(b))
209228

210229
end # modeule Quadmath

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Base.Test
1+
using Test
22
using Quadmath
33

44
for T in (Float64, Int32, Int64)

0 commit comments

Comments
 (0)