@@ -8,7 +8,7 @@ import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), ($),
8
8
binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod,
9
9
ndigits, promote_rule, rem, show, isqrt, string, isprime, powermod,
10
10
sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal,
11
- bin, oct, dec, hex, isequal, invmod, prevpow2, nextpow2, ndigits0z, widen, signed
11
+ bin, oct, dec, hex, isequal, invmod, prevpow2, nextpow2, ndigits0z, widen, signed, unsafe_trunc, trunc
12
12
13
13
if Clong == Int32
14
14
typealias ClongMax Union{Int8, Int16, Int32}
@@ -120,13 +120,23 @@ end
120
120
121
121
convert (:: Type{BigInt} , x:: Bool ) = BigInt (UInt (x))
122
122
123
- function convert ( :: Type{BigInt} , x :: Float64 )
124
- ! isinteger (x) && throw ( InexactError () )
123
+
124
+ function unsafe_trunc ( :: Type{BigInt} , x :: CdoubleMax )
125
125
z = BigInt ()
126
126
ccall ((:__gmpz_set_d , :libgmp ), Void, (Ptr{BigInt}, Cdouble), & z, x)
127
127
return z
128
128
end
129
129
130
+ function convert (:: Type{BigInt} , x:: CdoubleMax )
131
+ isinteger (x) || throw (InexactError ())
132
+ unsafe_trunc (BigInt,x)
133
+ end
134
+
135
+ function trunc (:: Type{BigInt} , x:: CdoubleMax )
136
+ isfinite (x) || throw (InexactError ())
137
+ unsafe_trunc (BigInt,x)
138
+ end
139
+
130
140
convert (:: Type{BigInt} , x:: Float16 ) = BigInt (Float64 (x))
131
141
convert (:: Type{BigInt} , x:: Float32 ) = BigInt (Float64 (x))
132
142
0 commit comments