A small tweak to lua random
This commit is contained in:
@@ -157,6 +157,10 @@ uint64_t hash_ints(uint64_t a, uint64_t b, uint64_t c, uint64_t d) {
|
||||
return h1;
|
||||
}
|
||||
|
||||
double hash_to_double(uint64_t hash) {
|
||||
return (hash >> (64-53)) * 0x1p-53;
|
||||
}
|
||||
|
||||
StringVec split(const eng::string &s, char sep) {
|
||||
StringVec result;
|
||||
int start = 0;
|
||||
@@ -498,6 +502,10 @@ LuaDefine(unittests_util, "", "some unit tests") {
|
||||
LuaAssertStrEq(L, util::hash_to_hex(util::HashValue(0x1234,0x789a)),
|
||||
"0000000000001234000000000000789a");
|
||||
|
||||
// Test hash_to_double
|
||||
LuaAssert(L, util::hash_to_double(0x1000000000000000) == 1.0/16.0);
|
||||
LuaAssert(L, util::hash_to_double(0x7000000000000000) == 7.0/16.0);
|
||||
LuaAssert(L, util::hash_to_double(0xF000000000000000) == 15.0/16.0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user