A small tweak to lua random

This commit is contained in:
2022-04-06 15:09:28 -04:00
parent 89365ea9ba
commit 453809b65c
3 changed files with 18 additions and 4 deletions

View File

@@ -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;
}