-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Float16: convert to various number types; round, trunc, floor, ceil.
These additional operations are needed to get the random and linalg tests closer to passing for the FloatRange change [#5636]. We really need to make a decision about how first-class we want Float16 to be. I'm starting to suspect that we should just bite the bullet and make all the things that work for other floating-point types work for the Float16 type also. It's just easier than having them be half-broken and try to explain that they're "just for storage".
- Loading branch information
1 parent
46fa6ea
commit aa724dc
Showing
2 changed files
with
12 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,16 @@ function convert(::Type{Float16}, val::Float32) | |
reinterpret(Float16, h) | ||
end | ||
|
||
for T in (Bool, Int128, Uint128, Complex, Rational) | ||
@eval convert(::Type{$T}, x::Float16) = convert($T,float32(x)) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
JeffBezanson
Member
|
||
end | ||
convert{T<:Number}(::Type{T}, x::Float16) = convert(T,float32(x)) | ||
|
||
round(x::Float16) = float16(round(float32(x))) | ||
trunc(x::Float16) = float16(trunc(float32(x))) | ||
floor(x::Float16) = float16(floor(float32(x))) | ||
ceil(x::Float16) = float16( ceil(float32(x))) | ||
|
||
isnan(x::Float16) = reinterpret(Uint16,x)&0x7fff > 0x7c00 | ||
isinf(x::Float16) = reinterpret(Uint16,x)&0x7fff == 0x7c00 | ||
isfinite(x::Float16) = reinterpret(Uint16,x)&0x7c00 != 0x7c00 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Converting to
Bool
andComplex
works without this patch. And I believe this patch will makeconvert(Complex, float16(x))
give aComplex64
instead of aComplex{Float16}
. Not sure we want that.