Skip to content

Commit 80a0318

Browse files
Update Quadmath.jl
1 parent 4acb7b8 commit 80a0318

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

src/Quadmath.jl

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This file is modelled after https://github.com/JuliaLang/julia/blob/master/base/mpfr.jl
2+
# which implements the BigFloat type
3+
14
module Quadmath
25

36
export Float128, Complex256
@@ -19,19 +22,15 @@ import
1922
import Base.GMP: ClongMax, CulongMax, CdoubleMax
2023

2124
bitstype 128 Float128 <: AbstractFloat
22-
#Note: with "<: AbstracFloat" multiplication of two Float128 numbers
23-
#mysteriously doesn't work!
2425

2526
typealias Complex256 Complex{Float128}
2627

2728
const libquadmath_wrapper = joinpath(dirname(@__FILE__),
2829
"..", "deps", "usr", "lib", "libquadmath_wrapper.so")
2930

30-
3131
widen(::Type{Float64}) = Float128
3232
widen(::Type{Float128}) = BigFloat
3333

34-
3534
convert(::Type{Float128}, x::Float128) = x
3635

3736
convert(::Type{Float128}, x::Clong) =
@@ -63,14 +62,12 @@ call(::Type{Float32}, x::Float128, r::RoundingMode) =
6362
call(::Type{Float16}, x::Float128, r::RoundingMode) =
6463
convert(Float16, call(Float32, x, r))
6564

66-
6765
#promote_rule{T<:Real}(::Type{Float128}, ::Type{T}) = Float128
6866
#promote_rule{T<:AbstractFloat}(::Type{Float128},::Type{T}) = Float128
6967

7068
promote_rule(::Type{Float128}, ::Type{Float32}) = Float128
7169
promote_rule(::Type{Float128}, ::Type{Float64}) = Float128
7270

73-
7471
function tryparse(::Type{Float128}, s::AbstractString, base::Int=0)
7572
Nullable(ccall((:set_str_q, libquadmath_wrapper), Float128, (Cstring, ), s))
7673
end
@@ -117,7 +114,7 @@ for (fJ, fC) in ((:+,:add), (:-,:sub), (:/,:div), (:*,:mul))
117114
end
118115
end
119116
end
120-
# 1st part of mysterious hack to get multiplication work
117+
# 2nd part of mysterious hack to get multiplication work
121118
# Defining * in this way works, very strange...
122119
*(x::Float128, y::Float128) = ccall(("mul_q",libquadmath_wrapper), Float128, (Float128, Float128), x, y)
123120

@@ -168,9 +165,6 @@ for (fJ, fC) in ((:+,:cadd), (:-,:csub), (:/,:cdiv), (:*,:cmul))
168165
end
169166
end
170167

171-
172-
173-
174168
# comparisons
175169
for (fJ, fC) in ((:<,:less), (:<=,:less_equal), (:(==),:equal), (:>=,:greater_equal), (:>,:greater))
176170
@eval begin
@@ -208,12 +202,10 @@ for (fJ, fC) in ((:<,:less), (:<=,:less_equal), (:(==),:equal), (:>=,:greater_eq
208202
end
209203
end
210204

211-
212205
function fma(x::Float128, y::Float128, z::Float128)
213206
ccall(("fma_q",libquadmath_wrapper), Float128, (Float128, Float128, Float128, ), x, y, z)
214207
end
215208

216-
217209
function -(x::Float128)
218210
ccall((:neg_q, libquadmath_wrapper), Float128, (Float128,), x)
219211
end
@@ -229,8 +221,6 @@ realmax(::Type{Float128}) = ccall(("realmax_q", libquadmath_wrapper), Float128,
229221
convert(::Type{Float128}, ::Irrational{:π}) = ccall(("pi_q", libquadmath_wrapper), Float128, (), )
230222
convert(::Type{Float128}, ::Irrational{:e}) = ccall(("e_q", libquadmath_wrapper), Float128, (), )
231223

232-
233-
234224
# unary functions
235225
for f in (:acos, :acosh, :asin, :asinh, :atan, :atanh, :cosh, :cos,
236226
:erf, :erfc, :exp, :expm1, :log, :log2, :log10, :sin, :sinh, :sqrt,
@@ -281,8 +271,6 @@ function cis(x::Float128)
281271
ccall((:ccis_q, libquadmath_wrapper), Complex256, (Float128,), x)
282272
end
283273

284-
285-
286274
function string(x::Float128)
287275
lng = 64
288276
buf = Array(UInt8, lng + 1)
@@ -305,5 +293,4 @@ end
305293
convert(::Type{Float128}, x::BigFloat) =
306294
ccall((:mpfr_get_float128_xxx, libquadmath_wrapper), Float128, (Ptr{BigFloat},Int32), &x, ROUNDING_MODE[end])
307295

308-
309-
end
296+
end # modeule Quadmath

0 commit comments

Comments
 (0)