-
-
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.
add conversions between float and int128 types
- Loading branch information
1 parent
06b0667
commit b198961
Showing
3 changed files
with
57 additions
and
15 deletions.
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
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 |
---|---|---|
|
@@ -123,8 +123,14 @@ convert(::Type{Int128}, x::Uint32 ) = box(Int128,zext_int(Uint128,unbox(Uint32,x | |
convert(::Type{Int128}, x::Int64 ) = box(Int128,sext_int(Int128,unbox(Int64,x))) | ||
convert(::Type{Int128}, x::Uint64 ) = box(Int128,zext_int(Uint128,unbox(Uint64,x))) | ||
convert(::Type{Int128}, x::Uint128) = box(Int128,unbox(Uint128,x)) | ||
# TODO: convert(::Type{Int128}, x::Float32) | ||
# TODO: convert(::Type{Int128}, x::Float64) | ||
function convert(::Type{Int128}, x::Float64) | ||
ax = abs(x) | ||
top = trunc(ldexp(ax,-64)) | ||
bot = ax - ldexp(top,64) | ||
n = int128(convert(Uint64,top))<<64 + int128(convert(Uint64,bot)) | ||
return x<0 ? -n : n | ||
end | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
JeffBezanson
Author
Member
|
||
convert(::Type{Int128}, x::Float32) = convert(Int128, float64(x)) | ||
|
||
convert(::Type{Uint128}, x::Bool ) = box(Uint128,zext_int(Int128,unbox(Bool,x))) | ||
convert(::Type{Uint128}, x::Int8 ) = box(Uint128,sext_int(Int128,unbox(Int8,x))) | ||
|
@@ -137,8 +143,14 @@ convert(::Type{Uint128}, x::Uint32 ) = box(Uint128,zext_int(Uint128,unbox(Uint32 | |
convert(::Type{Uint128}, x::Int64 ) = box(Uint128,sext_int(Int128,unbox(Int64,x))) | ||
convert(::Type{Uint128}, x::Uint64 ) = box(Uint128,zext_int(Uint128,unbox(Uint64,x))) | ||
convert(::Type{Uint128}, x::Int128 ) = box(Uint128,unbox(Int128,x)) | ||
# TODO: convert(::Type{Uint128}, x::Float32) | ||
# TODO: convert(::Type{Uint128}, x::Float64) | ||
function convert(::Type{Uint128}, x::Float64) | ||
ax = abs(x) | ||
top = trunc(ldexp(ax,-64)) | ||
bot = ax - ldexp(top,64) | ||
n = uint128(convert(Uint64,top))<<64 + uint128(convert(Uint64,bot)) | ||
return x<0 ? -n : n | ||
end | ||
convert(::Type{Uint128}, x::Float32) = convert(Uint128, float64(x)) | ||
|
||
convert(::Type{Signed}, x::Uint8 ) = convert(Int,x) | ||
convert(::Type{Signed}, x::Uint16 ) = convert(Int,x) | ||
|
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
This seems crazy expensive, but I guess there aren't any LLVM intrinsics for this.