Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: checked integer conversions #8420

Merged
merged 17 commits into from
Sep 29, 2014
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
effff39
check integer truncation (#5413) and make more operators follow T+T =…
JeffBezanson Sep 17, 2014
1d5050b
get numbers test passing with checked integer conversions and type-st…
JeffBezanson Sep 17, 2014
8495944
make a couple things safe for checked signed<->unsigned conversion
JeffBezanson Sep 17, 2014
e1690fc
check signed<->unsigned conversions
JeffBezanson Sep 18, 2014
c67837c
get dates tests passing with checked signed<->unsigned conversion
JeffBezanson Sep 19, 2014
06241fe
Merge branch 'master' of github.com:JuliaLang/julia into jb/checked_i…
JeffBezanson Sep 19, 2014
ec607da
get a few more things working with checked integer conversions
JeffBezanson Sep 19, 2014
50f1d10
Merge branch 'master' of github.com:JuliaLang/julia into jb/checked_i…
JeffBezanson Sep 25, 2014
16c2330
make signed() and unsigned() unchecked. check only in convert()
JeffBezanson Sep 25, 2014
9f0ef0d
add a bit of widening to reductions, to make up for the new
JeffBezanson Sep 25, 2014
b3e30f9
Merge branch 'master' of github.com:JuliaLang/julia into jb/checked_i…
JeffBezanson Sep 26, 2014
3336fbc
fix more cases of widening in reductions
JeffBezanson Sep 26, 2014
4d1c138
fix more issues with integer conversion in random number generation
JeffBezanson Sep 26, 2014
000f41e
Merge branch 'master' of github.com:JuliaLang/julia into jb/checked_i…
JeffBezanson Sep 26, 2014
8c39ad2
Merge branch 'master' of github.com:JuliaLang/julia into jb/checked_i…
JeffBezanson Sep 26, 2014
8321a9e
doc and test updates for checked integer conversions
JeffBezanson Sep 28, 2014
53b6dee
Merge branch 'master' of github.com:JuliaLang/julia into jb/checked_i…
JeffBezanson Sep 28, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ all: pcre_h.jl errno_h.jl build_h.jl.phony fenv_constants.jl file_constants.jl u

pcre_h.jl:
ifeq ($(USE_SYSTEM_PCRE), 1)
@$(call PRINT_PERL, $(CPP) -dM $(shell $(PCRE_CONFIG) --prefix)/include/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = uint32($$2)"' | sort > $@)
@$(call PRINT_PERL, $(CPP) -dM $(shell $(PCRE_CONFIG) --prefix)/include/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = int32($$2)"' | sort > $@)
else
@$(call PRINT_PERL, $(CPP) -dM $(build_includedir)/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = uint32($$2)"' | sort > $@)
@$(call PRINT_PERL, $(CPP) -dM $(build_includedir)/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = int32($$2)"' | sort > $@)
endif

errno_h.jl:
Expand Down
2 changes: 1 addition & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export
#ccall, cglobal, llvmcall, abs_float, add_float, add_int, and_int, ashr_int,
#box, bswap_int, checked_fptosi, checked_fptoui, checked_sadd,
#checked_smul, checked_ssub, checked_uadd, checked_umul, checked_usub,
#checked_trunc_sint, checked_trunc_uint,
#checked_trunc_sint, checked_trunc_uint, check_top_bit,
#nan_dom_err, copysign_float, ctlz_int, ctpop_int, cttz_int,
#div_float, eq_float, eq_int, eqfsi64, eqfui64, flipsign_int, select_value,
#sqrt_llvm, powi_llvm,
Expand Down
4 changes: 4 additions & 0 deletions base/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ char(x::FloatingPoint) = char(iround(x))

integer(x::Char) = int(x)

convert(::Type{Char}, x::Float16) = char(convert(Uint32, x))
convert(::Type{Char}, x::Float32) = char(convert(Uint32, x))
convert(::Type{Char}, x::Float64) = char(convert(Uint32, x))

## char promotions ##

promote_rule(::Type{Char}, ::Type{Int8}) = Int32
Expand Down
2 changes: 1 addition & 1 deletion base/dates/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ Base.promote_rule(::Type{Date},x::Type{DateTime}) = DateTime
Base.isless(x::Date,y::Date) = isless(value(x),value(y))
Base.isless(x::DateTime,y::DateTime) = isless(value(x),value(y))
Base.isless(x::TimeType,y::TimeType) = isless(promote(x,y)...)
==(x::TimeType,y::TimeType) = ===(promote(x,y)...)
==(x::TimeType,y::TimeType) = ===(promote(x,y)...)
4 changes: 2 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ end

empty!(t::ObjectIdDict) = (t.ht = cell(length(t.ht)); t)

_oidd_nextind(a, i) = int(ccall(:jl_eqtable_nextind, Csize_t, (Any, Csize_t), a, i))
_oidd_nextind(a, i) = reinterpret(Int,ccall(:jl_eqtable_nextind, Csize_t, (Any, Csize_t), a, i))

start(t::ObjectIdDict) = _oidd_nextind(t.ht, 0)
done(t::ObjectIdDict, i) = (i == -1)
Expand Down Expand Up @@ -385,7 +385,7 @@ function deserialize{K,V}(s, T::Type{Dict{K,V}})
return t
end

hashindex(key, sz) = (int(hash(key)) & (sz-1)) + 1
hashindex(key, sz) = (reinterpret(Int,hash(key)) & (sz-1)) + 1

isslotempty(h::Dict, i::Int) = h.slots[i] == 0x0
isslotfilled(h::Dict, i::Int) = h.slots[i] == 0x1
Expand Down
10 changes: 5 additions & 5 deletions base/float.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## conversions to floating-point ##

convert(::Type{Float32}, x::Int128) = float32(uint128(abs(x)))*(1-2(x<0))
convert(::Type{Float32}, x::Uint128) = float32(uint64(x)) + ldexp(float32(uint64(x>>>64)),64)
convert(::Type{Float32}, x::Int128) = float32(reinterpret(Uint128,abs(x)))*(1-2(x<0))
convert(::Type{Float32}, x::Uint128) = float32(uint64(x&0xffffffffffffffff)) + ldexp(float32(uint64(x>>>64)),64)
promote_rule(::Type{Float32}, ::Type{Int128} ) = Float32
promote_rule(::Type{Float32}, ::Type{Uint128}) = Float32

convert(::Type{Float64}, x::Int128) = float64(uint128(abs(x)))*(1-2(x<0))
convert(::Type{Float64}, x::Uint128) = float64(uint64(x)) + ldexp(float64(uint64(x>>>64)),64)
convert(::Type{Float64}, x::Int128) = float64(reinterpret(Uint128,abs(x)))*(1-2(x<0))
convert(::Type{Float64}, x::Uint128) = float64(uint64(x&0xffffffffffffffff)) + ldexp(float64(uint64(x>>>64)),64)
promote_rule(::Type{Float64}, ::Type{Int128} ) = Float64
promote_rule(::Type{Float64}, ::Type{Uint128}) = Float64

convert(::Type{Float16}, x::Union(Signed,Unsigned)) = convert(Float16, convert(Float32,x))
convert(::Type{Float16}, x::Integer) = convert(Float16, convert(Float32,x))
for t in (Bool,Char,Int8,Int16,Int32,Int64,Uint8,Uint16,Uint32,Uint64)
@eval promote_rule(::Type{Float16}, ::Type{$t}) = Float32
end
Expand Down
2 changes: 1 addition & 1 deletion base/hashing2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ end
function hash(s::IntSet, h::Uint)
h += uint(0x88989f1fc7dea67d)
h += hash(s.fill1s)
filln = s.fill1s ? uint32(-1) : uint32(0)
filln = s.fill1s ? ~zero(eltype(s.bits)) : zero(eltype(s.bits))
for x in s.bits
if x != filln
h = hash(x, h)
Expand Down
Loading