Skip to content

Commit

Permalink
Define typemin/max for 128-bit integer types.
Browse files Browse the repository at this point in the history
  julia> typemax(Int128)
  170141183460469231731687303715884105727

Man, that's a lot of digits.
  • Loading branch information
StefanKarpinski committed Jun 19, 2012
1 parent eef376a commit a5cde57
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ convert(::Type{Uint8}, x::Uint128) = boxui8(trunc8(unbox(Uint128,x)))
convert(::Type{Uint8}, x::Float32) = boxui8(trunc8(fpuiround32(unbox32(x))))
convert(::Type{Uint8}, x::Float64) = boxui8(trunc8(fpuiround64(unbox64(x))))

convert(::Type{Int16}, x::Bool ) = boxsi16(sext16(unbox8(x)))
convert(::Type{Int16}, x::Bool ) = boxsi16(zext16(unbox8(x)))
convert(::Type{Int16}, x::Int8 ) = boxsi16(sext16(unbox8(x)))
convert(::Type{Int16}, x::Uint8 ) = boxsi16(zext16(unbox8(x)))
convert(::Type{Int16}, x::Uint16 ) = boxsi16(unbox16(x))
Expand All @@ -42,7 +42,7 @@ convert(::Type{Int16}, x::Uint128) = boxsi16(trunc16(unbox(Uint128,x)))
convert(::Type{Int16}, x::Float32) = boxsi16(trunc16(fpsiround32(unbox32(x))))
convert(::Type{Int16}, x::Float64) = boxsi16(trunc16(fpsiround64(unbox64(x))))

convert(::Type{Uint16}, x::Bool ) = boxui16(sext16(unbox8(x)))
convert(::Type{Uint16}, x::Bool ) = boxui16(zext16(unbox8(x)))
convert(::Type{Uint16}, x::Int8 ) = boxui16(sext16(unbox8(x)))
convert(::Type{Uint16}, x::Uint8 ) = boxui16(zext16(unbox8(x)))
convert(::Type{Uint16}, x::Int16 ) = boxui16(unbox16(x))
Expand All @@ -56,7 +56,7 @@ convert(::Type{Uint16}, x::Uint128) = boxui16(trunc16(unbox(Uint128,x)))
convert(::Type{Uint16}, x::Float32) = boxui16(trunc16(fpuiround32(unbox32(x))))
convert(::Type{Uint16}, x::Float64) = boxui16(trunc16(fpuiround64(unbox64(x))))

convert(::Type{Int32}, x::Bool ) = boxsi32(sext32(unbox8(x)))
convert(::Type{Int32}, x::Bool ) = boxsi32(zext32(unbox8(x)))
convert(::Type{Int32}, x::Int8 ) = boxsi32(sext32(unbox8(x)))
convert(::Type{Int32}, x::Uint8 ) = boxsi32(zext32(unbox8(x)))
convert(::Type{Int32}, x::Int16 ) = boxsi32(sext32(unbox16(x)))
Expand All @@ -70,7 +70,7 @@ convert(::Type{Int32}, x::Uint128) = boxsi32(trunc32(unbox(Uint128,x)))
convert(::Type{Int32}, x::Float32) = boxsi32(fpsiround32(unbox32(x)))
convert(::Type{Int32}, x::Float64) = boxsi32(trunc32(fpsiround64(unbox64(x))))

convert(::Type{Uint32}, x::Bool ) = boxui32(sext32(unbox8(x)))
convert(::Type{Uint32}, x::Bool ) = boxui32(zext32(unbox8(x)))
convert(::Type{Uint32}, x::Int8 ) = boxui32(sext32(unbox8(x)))
convert(::Type{Uint32}, x::Uint8 ) = boxui32(zext32(unbox8(x)))
convert(::Type{Uint32}, x::Int16 ) = boxui32(sext32(unbox16(x)))
Expand All @@ -84,7 +84,7 @@ convert(::Type{Uint32}, x::Uint128) = boxui32(trunc32(unbox(Uint128,x)))
convert(::Type{Uint32}, x::Float32) = boxui32(fpuiround32(unbox32(x)))
convert(::Type{Uint32}, x::Float64) = boxui32(trunc32(fpuiround64(unbox64(x))))

convert(::Type{Int64}, x::Bool ) = boxsi64(sext64(unbox8(x)))
convert(::Type{Int64}, x::Bool ) = boxsi64(zext64(unbox8(x)))
convert(::Type{Int64}, x::Int8 ) = boxsi64(sext64(unbox8(x)))
convert(::Type{Int64}, x::Uint8 ) = boxsi64(zext64(unbox8(x)))
convert(::Type{Int64}, x::Int16 ) = boxsi64(sext64(unbox16(x)))
Expand All @@ -98,7 +98,7 @@ convert(::Type{Int64}, x::Uint128) = boxsi64(trunc64(unbox(Uint128,x)))
convert(::Type{Int64}, x::Float32) = boxsi64(fpsiround64(fpext64(unbox32(x))))
convert(::Type{Int64}, x::Float64) = boxsi64(fpsiround64(unbox64(x)))

convert(::Type{Uint64}, x::Bool ) = boxui64(sext64(unbox8(x)))
convert(::Type{Uint64}, x::Bool ) = boxui64(zext64(unbox8(x)))
convert(::Type{Uint64}, x::Int8 ) = boxui64(sext64(unbox8(x)))
convert(::Type{Uint64}, x::Uint8 ) = boxui64(zext64(unbox8(x)))
convert(::Type{Uint64}, x::Int16 ) = boxui64(sext64(unbox16(x)))
Expand All @@ -112,7 +112,7 @@ convert(::Type{Uint64}, x::Uint128) = boxui64(trunc64(unbox(Uint128,x)))
convert(::Type{Uint64}, x::Float32) = boxui64(fpuiround64(fpext64(unbox32(x))))
convert(::Type{Uint64}, x::Float64) = boxui64(fpuiround64(unbox64(x)))

convert(::Type{Int128}, x::Bool ) = box(Int128,sext_int(Int128,unbox8(x)))
convert(::Type{Int128}, x::Bool ) = box(Int128,zext_int(Int128,unbox8(x)))
convert(::Type{Int128}, x::Int8 ) = box(Int128,sext_int(Int128,unbox8(x)))
convert(::Type{Int128}, x::Uint8 ) = box(Int128,zext_int(Uint128,unbox8(x)))
convert(::Type{Int128}, x::Int16 ) = box(Int128,sext_int(Int128,unbox16(x)))
Expand All @@ -126,7 +126,7 @@ convert(::Type{Int128}, x::Uint128) = box(Int128,unbox(Uint128,x))
# TODO: convert(::Type{Int128}, x::Float32)
# TODO: convert(::Type{Int128}, x::Float64)

convert(::Type{Uint128}, x::Bool ) = box(Uint128,sext_int(Int128,unbox8(x)))
convert(::Type{Uint128}, x::Bool ) = box(Uint128,zext_int(Int128,unbox8(x)))
convert(::Type{Uint128}, x::Int8 ) = box(Uint128,sext_int(Int128,unbox8(x)))
convert(::Type{Uint128}, x::Uint8 ) = box(Uint128,zext_int(Uint128,unbox8(x)))
convert(::Type{Uint128}, x::Int16 ) = box(Uint128,sext_int(Int128,unbox16(x)))
Expand Down Expand Up @@ -549,7 +549,12 @@ typemax(::Type{Uint32}) = uint32(4294967295)
typemax(::Type{Int64 }) = 9223372036854775807
typemin(::Type{Uint64}) = uint64(0)
typemax(::Type{Uint64}) = 0xffffffffffffffff
# TODO: typemin/max for Int128, Uint128
@eval begin
typemin(::Type{Uint128}) = uint128(0)
typemax(::Type{Uint128}) = $(uint128(-1))
typemin(::Type{Int128} ) = $(int128((uint128(-1))>>int32(1))+int128(1))
typemax(::Type{Int128} ) = $(int128((uint128(-1))>>int32(1)))
end

sizeof(::Type{Int8}) = 1
sizeof(::Type{Uint8}) = 1
Expand Down

0 comments on commit a5cde57

Please sign in to comment.