Skip to content

Commit 0559106

Browse files
fixed multipl. problem but don't understand how...
1 parent a1e5c36 commit 0559106

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/Quadmath.jl

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Quadmath
33
export Float128, Complex256
44

55
import
6-
Base: +, -, (*), /, <, <=, ==, >, >=, ^, convert, promote_rule,
6+
Base: (*), +, -, /, <, <=, ==, >, >=, ^, convert, promote_rule,
77
string, print, show, showcompact, tryparse,
88
acos, acosh, asin, asinh, atan, atanh, cosh, cos,
99
erf, erfc, expm1, log, log2, log10, sin, sinh, sqrt,
@@ -18,7 +18,7 @@ import
1818

1919
import Base.GMP: ClongMax, CulongMax, CdoubleMax
2020

21-
bitstype 128 Float128 <: AbstractFloat # this is in base/boot.jl
21+
bitstype 128 Float128 <: AbstractFloat
2222
#Note: with "<: AbstracFloat" multiplication of two Float128 numbers
2323
#mysteriously doesn't work!
2424

@@ -27,6 +27,11 @@ typealias Complex256 Complex{Float128}
2727
const libquadmath_wrapper = joinpath(dirname(@__FILE__),
2828
"..", "deps", "usr", "lib", "libquadmath_wrapper.so")
2929

30+
31+
widen(::Type{Float64}) = Float128
32+
widen(::Type{Float128}) = BigFloat
33+
34+
3035
convert(::Type{Float128}, x::Float128) = x
3136

3237
convert(::Type{Float128}, x::Clong) =
@@ -59,21 +64,30 @@ call(::Type{Float16}, x::Float128, r::RoundingMode) =
5964
convert(Float16, call(Float32, x, r))
6065

6166

62-
promote_rule{T<:Real}(::Type{Float128}, ::Type{T}) = Float128
63-
promote_rule{T<:AbstractFloat}(::Type{Float128},::Type{T}) = Float128
67+
#promote_rule{T<:Real}(::Type{Float128}, ::Type{T}) = Float128
68+
#promote_rule{T<:AbstractFloat}(::Type{Float128},::Type{T}) = Float128
69+
70+
promote_rule(::Type{Float128}, ::Type{Float32}) = Float128
71+
promote_rule(::Type{Float128}, ::Type{Float64}) = Float128
6472

6573

6674
function tryparse(::Type{Float128}, s::AbstractString, base::Int=0)
6775
Nullable(ccall((:set_str_q, libquadmath_wrapper), Float128, (Cstring, ), s))
6876
end
6977

7078
# Basic arithmetic without promotion
71-
for (fJ, fC) in ((:+,:add), (:-,:sub), (:/,:div), (:(*),:mul))
72-
@eval begin
73-
#Float128
74-
function ($fJ)(x::Float128, y::Float128)
75-
ccall(($(string(fC,:_q)),libquadmath_wrapper), Float128, (Float128, Float128), x, y)
79+
for (fJ, fC) in ((:+,:add), (:-,:sub), (:/,:div), (:*,:mul))
80+
81+
#Float128
82+
if (fC!=(:mul)) # 1st part of mysterious hack to get multiplication work
83+
@eval begin
84+
function ($fJ)(x::Float128, y::Float128)
85+
ccall(($(string(fC,:_q)),libquadmath_wrapper), Float128, (Float128, Float128), x, y)
86+
end
7687
end
88+
end
89+
90+
@eval begin
7791

7892
#Unsigned Integer
7993
function ($fJ)(x::Float128, y::CulongMax)
@@ -103,9 +117,12 @@ for (fJ, fC) in ((:+,:add), (:-,:sub), (:/,:div), (:(*),:mul))
103117
end
104118
end
105119
end
120+
# 1st part of mysterious hack to get multiplication work
121+
# Defining * in this way works, very strange...
122+
*(x::Float128, y::Float128) = ccall(("mul_q",libquadmath_wrapper), Float128, (Float128, Float128), x, y)
106123

107124
# Basic complex arithmetic without promotion
108-
for (fJ, fC) in ((:+,:cadd), (:-,:csub), (:/,:cdiv), (:(*),:cmul))
125+
for (fJ, fC) in ((:+,:cadd), (:-,:csub), (:/,:cdiv), (:*,:cmul))
109126
@eval begin
110127
#Float128
111128
function ($fJ)(x::Complex256, y::Complex256)

0 commit comments

Comments
 (0)