Skip to content

Commit

Permalink
Print unsigned integers as hex literals with apt width.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Dec 14, 2011
1 parent 53f9f0f commit 1051578
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 8 additions & 1 deletion j/show.j
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ show(tn::TypeName) = show(tn.name)
show(::Nothing) = print("nothing")
show(b::Bool) = print(b ? "true" : "false")
show(n::Int) = show(int64(n))
show(n::Uint) = show(uint64(n))

function show_trailing_hex(n::Uint64, ndig::Int)
for s = ndig-1:-1:0
d = (n >> 4*s) & uint64(0xf)
print("0123456789abcdef"[long(d+1)])
end
end
show(n::Uint) = (print("0x"); show_trailing_hex(uint64(n),sizeof(n)<<1))

show_float64(f::Float64, ndig) =
ccall(:jl_show_float, Void, (Float64, Int32), f, int32(ndig))
Expand Down
1 change: 0 additions & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,6 @@ void jl_init_builtins(void)

add_builtin_method1(jl_show_gf, (jl_type_t*)jl_any_type, jl_f_show_any);
add_builtin_method1(jl_show_gf, (jl_type_t*)jl_int64_type, jl_f_show_int64);
add_builtin_method1(jl_show_gf, (jl_type_t*)jl_uint64_type, jl_f_show_uint64);

jl_convert_gf = jl_new_generic_function(jl_symbol("convert"));
jl_add_method(jl_convert_gf,
Expand Down
2 changes: 1 addition & 1 deletion test/core.j
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ end
@assert parse_hex("DeadBeef") == 3735928559
# bits types, printing numbers
@assert string(uint32(-1)) == "4294967295"
@assert string(uint32(-1)) == "0xffffffff"
if WORD_SIZE == 64
@assert isa((()->box(Ptr{Int8},unbox64(int64(0))))(), Ptr{Int8})
else
Expand Down

0 comments on commit 1051578

Please sign in to comment.