Navigation Menu

Skip to content

Commit

Permalink
Add Float::hash(). (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Jan 5, 2015
1 parent 6f663f2 commit c52ba4a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/grnxx/data_types/scalar/float.hpp
Expand Up @@ -45,6 +45,18 @@ class Float {
return std::isnan(raw_);
}

uint64_t hash() const {
double normalized_raw = (raw_ != 0.0) ? raw_ : 0.0;
uint64_t x;
std::memcpy(&x, &normalized_raw, sizeof(x));
x ^= x >> 33;
x *= uint64_t(0xFF51AFD7ED558CCDULL);
x ^= x >> 33;
x *= uint64_t(0xC4CEB9FE1A85EC53ULL);
x ^= x >> 33;
return x;
}

// -- Unary operators --

constexpr Float operator+() const {
Expand Down

0 comments on commit c52ba4a

Please sign in to comment.