@@ -15,9 +15,11 @@ import Base: (*), +, -, /, <, <=, ==, ^, convert,
1515 copysign, flipsign, max, min, hypot, abs,
1616 ldexp, frexp, modf, nextfloat, eps,
1717 isinf, isnan, isfinite, isinteger,
18- floatmin, floatmax, precision, signbit,
18+ floatmin, floatmax, precision, signbit, maxintfloat,
1919 Int32, Int64, Float64, BigFloat, BigInt
2020
21+ using Random
22+
2123if Sys. isapple ()
2224 const quadoplib = " libquadmath.0"
2325 const libquadmath = " libquadmath.0"
@@ -361,6 +363,8 @@ eps(::Type{Float128}) = reinterpret(Float128, 0x3f8f_0000_0000_0000_0000_0000_00
361363floatmin (:: Type{Float128} ) = reinterpret (Float128, 0x0001_0000_0000_0000_0000_0000_0000_0000 )
362364floatmax (:: Type{Float128} ) = reinterpret (Float128, 0x7ffe_ffff_ffff_ffff_ffff_ffff_ffff_ffff )
363365
366+ maxintfloat (:: Type{Float128} ) = Float128 (0x0002_0000_0000_0000_0000_0000_0000_0000 )
367+
364368ldexp (x:: Float128 , n:: Cint ) =
365369 Float128 (@ccall (libquadmath. ldexpq (x:: Cfloat128 , n:: Cint ):: Cfloat128 ))
366370ldexp (x:: Float128 , n:: Integer ) =
@@ -543,6 +547,14 @@ promote_rule(::Type{Float128}, ::Type{<:Integer}) = Float128
543547# widen(::Type{Float64}) = Float128
544548widen (:: Type{Float128} ) = BigFloat
545549
550+ function Random. rand (rng:: AbstractRNG , s:: Random.SamplerTrivial{Random.CloseOpen01{Float128}} )
551+ u = rand (rng, UInt128)
552+ x = (reinterpret (Float128, u & Base. significand_mask (Float128)
553+ | Base. exponent_one (Float128))
554+ - one (Float128))
555+ return x
556+ end
557+
546558# TODO : need to do this better
547559function parse (:: Type{Float128} , s:: AbstractString )
548560 Float128 (@ccall (libquadmath. strtoflt128 (s:: Cstring , C_NULL :: Ptr{Ptr{Cchar}} ):: Cfloat128 ))
0 commit comments