@@ -13,9 +13,10 @@ import Base: (*), +, -, /, <, <=, ==, ^, convert,
13
13
tan, tanh,
14
14
ceil, floor, trunc, round, fma,
15
15
copysign, flipsign, max, min, hypot, abs,
16
- ldexp, frexp, nextfloat,
17
- eps, isinf, isnan, isfinite, floatmin, floatmax, precision, signbit,
18
- Int32,Int64,Float64,BigFloat
16
+ ldexp, frexp, modf, nextfloat, eps,
17
+ isinf, isnan, isfinite, isinteger,
18
+ floatmin, floatmax, precision, signbit,
19
+ Int32, Int64, Float64, BigFloat, BigInt
19
20
20
21
if Sys. isapple ()
21
22
const quadoplib = " libquadmath.0"
@@ -186,6 +187,7 @@ isinf(x::Float128) =
186
187
0 != ccall ((:isinfq ,libquadmath), Cint, (Cfloat128, ), x)
187
188
isfinite (x:: Float128 ) =
188
189
0 != ccall ((:finiteq ,libquadmath), Cint, (Cfloat128, ), x)
190
+ isinteger (x:: Float128 ) = isfinite (x) && x === trunc (x)
189
191
190
192
signbit (x:: Float128 ) = signbit (reinterpret (Int128, x))
191
193
precision (:: Type{Float128} ) = 113
@@ -194,7 +196,6 @@ eps(::Type{Float128}) = reinterpret(Float128, 0x3f8f_0000_0000_0000_0000_0000_00
194
196
floatmin (:: Type{Float128} ) = reinterpret (Float128, 0x0001_0000_0000_0000_0000_0000_0000_0000 )
195
197
floatmax (:: Type{Float128} ) = reinterpret (Float128, 0x7ffe_ffff_ffff_ffff_ffff_ffff_ffff_ffff )
196
198
197
-
198
199
ldexp (x:: Float128 , n:: Cint ) =
199
200
Float128 (ccall ((:ldexpq , libquadmath), Cfloat128, (Cfloat128, Cint), x, n))
200
201
ldexp (x:: Float128 , n:: Integer ) =
@@ -206,6 +207,13 @@ function frexp(x::Float128)
206
207
return y, Int (r[])
207
208
end
208
209
210
+ function modf (x:: Float128 )
211
+ isinf (x) && return (zero (Float128), x)
212
+ ipart = trunc (x)
213
+ fpart = x - ipart
214
+ return fpart, ipart
215
+ end
216
+
209
217
significand (x:: Float128 ) = frexp (x)[1 ] * 2
210
218
function exponent (x:: Float128 )
211
219
! isfinite (x) && throw (DomainError (" Cannot be NaN or Inf." ))
@@ -224,7 +232,7 @@ function nextfloat(f::Float128, d::Integer)
224
232
fu = unsigned (fi & typemax (fi))
225
233
226
234
dneg = d < 0
227
- da = uabs (d)
235
+ da = Base . uabs (d)
228
236
if da > typemax (U)
229
237
fneg = dneg
230
238
fu = fumax
@@ -344,7 +352,11 @@ function Float128(x::BigFloat)
344
352
return copysign (z,x)
345
353
end
346
354
347
-
355
+ function BigInt (x:: Float128 )
356
+ ! isinteger (x) && throw (InexactError (:BigInt , x))
357
+ BigInt (BigFloat (x, precision= precision (Float128)))
358
+ end
359
+ Float128 (x:: BigInt ) = Float128 (BigFloat (x, precision= precision (Float128)))
348
360
349
361
promote_rule (:: Type{Float128} , :: Type{Float16} ) = Float128
350
362
promote_rule (:: Type{Float128} , :: Type{Float32} ) = Float128
0 commit comments