Skip to content

Commit

Permalink
Fix incorrect truncation of floating-point data
Browse files Browse the repository at this point in the history
If the entire parenthesized division expression is cast to float, as it
was prior to this commit, C performs truncating integer division before
converting to float, which always leads to a result of zero.  `git-blame'
traces the bug to commit d5ed7e7, which
added the faulty parentheses as a matter of style. No parentheses are
necessary, since increments have higher precedence than type-casts,
type-casts have higher precedence than division, and division has
higher precedence than comparison. The operations will execute in the
desired order.
  • Loading branch information
bl0ckeduser committed Aug 12, 2013
1 parent 6ca1ec8 commit 716936a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libtvm/tvm_htab.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int htab_add(tvm_htab_t *htab, const char *k, int v)

/* Increase bucket count and rehash if the
load factor is too high */
if((float)(++htab->num_nodes / htab->size) > HTAB_LOAD_FACTOR)
if((float)++htab->num_nodes / htab->size > HTAB_LOAD_FACTOR)
htab_rehash(htab, htab->num_nodes * 2);

return 0;
Expand Down

0 comments on commit 716936a

Please sign in to comment.