Skip to content

Commit b7b85ff

Browse files
committed
Tweak isinf code, now independent of hardware
1 parent b779008 commit b7b85ff

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

base/float.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ isfinite(x::Float16) = reinterpret(UInt16,x)&0x7c00 != 0x7c00
503503
isfinite(x::Real) = decompose(x)[3] != 0
504504
isfinite(x::Integer) = true
505505

506-
isinf(x::Real) = !isnan(x) & !isfinite(x)
506+
isinf(x::Real) = (reinterpret(Unsigned, x) & ~sign_mask(T)) == exponent_mask(T)
507507

508508
## hashing small, built-in numeric types ##
509509

base/math.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,25 +411,25 @@ Return `(x,exp)` such that `x` has a magnitude in the interval ``[1/2, 1)`` or 0
411411
and `val` is equal to ``x \\times 2^{exp}``.
412412
"""
413413
function frexp{T<:AbstractFloat}(x::T)
414-
xu = reinterpret(Unsigned, x)
414+
xu = reinterpret(Unsigned,x)
415415
xe = xu & exponent_mask(T)
416-
xe == exponent_mask(T) && return x, 0 # NaN or Inf
417416
k = Int(xe >> significand_bits(T))
418417
if xe == 0 # x is subnormal
418+
x == 0 && return x, 0
419419
xs = xu & sign_mask(T)
420420
xu $= xs
421-
xu == 0 && return x, 0 # +-0
422-
m = (leading_zeros(xu) - exponent_bits(T)) % UInt
421+
m = leading_zeros(xu)-exponent_bits(T)
423422
xu <<= m
424423
xu $= xs
425-
k = 1 - (m % Int)
424+
k = 1-m
425+
elseif xe == exponent_mask(T) # NaN or Inf
426+
return x,0
426427
end
427-
k -= (exponent_bias(T) - 1)
428+
k -= (exponent_bias(T)-1)
428429
xu = (xu & ~exponent_mask(T)) | exponent_half(T)
429-
return reinterpret(T, xu), k
430+
reinterpret(T,xu), k
430431
end
431432

432-
433433
function frexp{T<:AbstractFloat}(A::Array{T})
434434
F = similar(A)
435435
E = Array{Int}(size(A))

0 commit comments

Comments
 (0)