luke-jr/bfgminer — pull request #539 by dvitas (2014-08-14 10:00:16+00:00)
Title: Fix target calculation from diff < 1.0 in test_hash()

Looks like the target calculation in test_hash() is completely broken for diff < 1. At least it makes no sense to me. With lower difficulty you must have bigger target and vice versa.
The definition of difficulty:
diff = 0x00000000FFFFFF...FF / target,
which means that:
target = 0x00000000FFFFFF...FF / diff,
which approximately equals to:
target = 0x000000010000..00 / diff,

In case of test_hash() function, where we are using only MSW, it gives us (by dropping all the lower words and leaving only the most significant one):
target_MSW= 0x00000001 / diff.

That's why the fix :)