1
+ # This file is modelled after https://github.com/JuliaLang/julia/blob/master/base/mpfr.jl
2
+ # which implements the BigFloat type
3
+
1
4
module Quadmath
2
5
3
6
export Float128, Complex256
@@ -19,19 +22,15 @@ import
19
22
import Base. GMP: ClongMax, CulongMax, CdoubleMax
20
23
21
24
bitstype 128 Float128 <: AbstractFloat
22
- # Note: with "<: AbstracFloat" multiplication of two Float128 numbers
23
- # mysteriously doesn't work!
24
25
25
26
typealias Complex256 Complex{Float128}
26
27
27
28
const libquadmath_wrapper = joinpath (dirname (@__FILE__ ),
28
29
" .." , " deps" , " usr" , " lib" , " libquadmath_wrapper.so" )
29
30
30
-
31
31
widen (:: Type{Float64} ) = Float128
32
32
widen (:: Type{Float128} ) = BigFloat
33
33
34
-
35
34
convert (:: Type{Float128} , x:: Float128 ) = x
36
35
37
36
convert (:: Type{Float128} , x:: Clong ) =
@@ -63,14 +62,12 @@ call(::Type{Float32}, x::Float128, r::RoundingMode) =
63
62
call (:: Type{Float16} , x:: Float128 , r:: RoundingMode ) =
64
63
convert (Float16, call (Float32, x, r))
65
64
66
-
67
65
# promote_rule{T<:Real}(::Type{Float128}, ::Type{T}) = Float128
68
66
# promote_rule{T<:AbstractFloat}(::Type{Float128},::Type{T}) = Float128
69
67
70
68
promote_rule (:: Type{Float128} , :: Type{Float32} ) = Float128
71
69
promote_rule (:: Type{Float128} , :: Type{Float64} ) = Float128
72
70
73
-
74
71
function tryparse (:: Type{Float128} , s:: AbstractString , base:: Int = 0 )
75
72
Nullable (ccall ((:set_str_q , libquadmath_wrapper), Float128, (Cstring, ), s))
76
73
end
@@ -117,7 +114,7 @@ for (fJ, fC) in ((:+,:add), (:-,:sub), (:/,:div), (:*,:mul))
117
114
end
118
115
end
119
116
end
120
- # 1st part of mysterious hack to get multiplication work
117
+ # 2nd part of mysterious hack to get multiplication work
121
118
# Defining * in this way works, very strange...
122
119
* (x:: Float128 , y:: Float128 ) = ccall ((" mul_q" ,libquadmath_wrapper), Float128, (Float128, Float128), x, y)
123
120
@@ -168,9 +165,6 @@ for (fJ, fC) in ((:+,:cadd), (:-,:csub), (:/,:cdiv), (:*,:cmul))
168
165
end
169
166
end
170
167
171
-
172
-
173
-
174
168
# comparisons
175
169
for (fJ, fC) in ((:< ,:less ), (:<= ,:less_equal ), (:(== ),:equal ), (:>= ,:greater_equal ), (:> ,:greater ))
176
170
@eval begin
@@ -208,12 +202,10 @@ for (fJ, fC) in ((:<,:less), (:<=,:less_equal), (:(==),:equal), (:>=,:greater_eq
208
202
end
209
203
end
210
204
211
-
212
205
function fma (x:: Float128 , y:: Float128 , z:: Float128 )
213
206
ccall ((" fma_q" ,libquadmath_wrapper), Float128, (Float128, Float128, Float128, ), x, y, z)
214
207
end
215
208
216
-
217
209
function - (x:: Float128 )
218
210
ccall ((:neg_q , libquadmath_wrapper), Float128, (Float128,), x)
219
211
end
@@ -229,8 +221,6 @@ realmax(::Type{Float128}) = ccall(("realmax_q", libquadmath_wrapper), Float128,
229
221
convert (:: Type{Float128} , :: Irrational{:π} ) = ccall ((" pi_q" , libquadmath_wrapper), Float128, (), )
230
222
convert (:: Type{Float128} , :: Irrational{:e} ) = ccall ((" e_q" , libquadmath_wrapper), Float128, (), )
231
223
232
-
233
-
234
224
# unary functions
235
225
for f in (:acos , :acosh , :asin , :asinh , :atan , :atanh , :cosh , :cos ,
236
226
:erf , :erfc , :exp , :expm1 , :log , :log2 , :log10 , :sin , :sinh , :sqrt ,
@@ -281,8 +271,6 @@ function cis(x::Float128)
281
271
ccall ((:ccis_q , libquadmath_wrapper), Complex256, (Float128,), x)
282
272
end
283
273
284
-
285
-
286
274
function string (x:: Float128 )
287
275
lng = 64
288
276
buf = Array (UInt8, lng + 1 )
305
293
convert (:: Type{Float128} , x:: BigFloat ) =
306
294
ccall ((:mpfr_get_float128_xxx , libquadmath_wrapper), Float128, (Ptr{BigFloat},Int32), & x, ROUNDING_MODE[end ])
307
295
308
-
309
- end
296
+ end # modeule Quadmath
0 commit comments