Skip to content

Commit 4ae6473

Browse files
RalphASsimonbyrne
authored andcommitted
Inf128, typemin/max (#30)
* Inf128, typemin/max * revise test sequence to isolate fma issue
1 parent 124cb8f commit 4ae6473

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/Quadmath.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Quadmath
22
using Requires
33

4-
export Float128, ComplexF128
4+
export Float128, ComplexF128, Inf128
55

66
import Base: (*), +, -, /, <, <=, ==, ^, convert,
77
reinterpret, sign_mask, exponent_mask, exponent_one, exponent_half,
@@ -13,7 +13,7 @@ import Base: (*), +, -, /, <, <=, ==, ^, convert,
1313
tan, tanh,
1414
ceil, floor, trunc, round, fma,
1515
copysign, flipsign, max, min, hypot, abs,
16-
ldexp, frexp, modf, nextfloat, eps,
16+
ldexp, frexp, modf, nextfloat, typemax, typemin, eps,
1717
isinf, isnan, isfinite, isinteger,
1818
floatmin, floatmax, precision, signbit, maxintfloat,
1919
Int32, Int64, Float64, BigFloat, BigInt
@@ -368,6 +368,14 @@ floatmin(::Type{Float128}) = reinterpret(Float128, 0x0001_0000_0000_0000_0000_00
368368
floatmax(::Type{Float128}) = reinterpret(Float128, 0x7ffe_ffff_ffff_ffff_ffff_ffff_ffff_ffff)
369369

370370
maxintfloat(::Type{Float128}) = Float128(0x0002_0000_0000_0000_0000_0000_0000_0000)
371+
"""
372+
Inf128
373+
374+
Positive infinity of type [`Float128`](@ref).
375+
"""
376+
const Inf128 = reinterpret(Float128, 0x7fff_0000_0000_0000_0000_0000_0000_0000)
377+
typemax(::Type{Float128}) = Inf128
378+
typemin(::Type{Float128}) = -Inf128
371379

372380
ldexp(x::Float128, n::Cint) =
373381
Float128(@ccall(libquadmath.ldexpq(x::Cfloat128, n::Cint)::Cfloat128))

test/runtests.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ end
9292
@test x+y == ipart+fpart
9393
end
9494

95+
isnan128(x) = isa(x, Float128) && isnan(x)
96+
isinf128(x) = isa(x, Float128) && isinf(x)
97+
98+
@testset "nonfinite" begin
99+
Zero = Float128(0)
100+
One = Float128(1)
101+
huge = floatmax(Float128)
102+
myinf = huge + huge
103+
myminf = -myinf
104+
@test isinf128(myinf)
105+
@test isnan128(Zero / Zero)
106+
@test isinf128(One / Zero)
107+
@test isnan128(myinf - myinf)
108+
@test isnan128(myinf + myminf)
109+
@test Inf128 === myinf
110+
@test typemax(Float128) === myinf
111+
@test typemin(Float128) === myminf
112+
end
113+
95114
@testset "transcendental etc. calls" begin
96115
# at least enough to cover all the wrapping code
97116
x = sqrt(Float128(2.0))
@@ -101,7 +120,14 @@ end
101120
@test abs(x) == x
102121
@test hypot(Float128(3),Float128(4)) == Float128(5)
103122
@test atan(x,x) Float128(pi) / 4
123+
h = floatmax(Float128)
124+
@test isinf(h+h)
104125
@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)
130+
end
105131
end
106132

107133
@testset "misc. math" begin

0 commit comments

Comments
 (0)