Python interpreting equal values as non-equal -
for part of code, inside for loop
s = 'cl_num = %d, prev_cl_num = %d\n' % (cl_num, prev_cl_num); fd.write( s ); if cl_num != prev_cl_num: bb.instructions[i].is_cache_miss = 1; s = 'instruction %x cache miss, cl_num = %d, prev_cl_num = %d, base_cache_line = %d\n' % (bb.instructions[i].address, cl_num, prev_cl_num, base_cache_line); fd.write( s ); bb.instructions[i].cache_line = cl_num - base_cache_line; prev_cl_num = cl_num;
i output, in fd file,
cl_num = 65557, prev_cl_num = 65557 instruction 400558 cache miss, cl_num = 65557, prev_cl_num = 65557, base_cache_line = 65557 cl_num = 65557, prev_cl_num = 65557 instruction 400560 cache miss, cl_num = 65557, prev_cl_num = 65557, base_cache_line = 65557 cl_num = 65557, prev_cl_num = 65557 instruction 400568 cache miss, cl_num = 65557, prev_cl_num = 65557, base_cache_line = 65557 cl_num = 65557, prev_cl_num = 65557 instruction 400570 cache miss, cl_num = 65557, prev_cl_num = 65557, base_cache_line = 65557
you see, condition cl_num != prev_cl_num
gets evaluated true
when cl_num
equal prev_cl_num
. why so?
you have floating point values, write integer portion file:
>>> '%d' % 3.3 '3'
note how .3
decimal portion has been ignored; %d
calls int()
on interpolated value.
when writing debugging values, use repr()
, or %r
in formatting:
s = 'cl_num = %r, prev_cl_num = %r\n' % (cl_num, prev_cl_num);
repr()
on float values formats them if using %17g
formatter; 17 decimals shown, scientific notation used when exponent 17 or up.
Comments
Post a Comment