static_cast<unsigned int>(double) is undefined for negative values -- need bounds checking. (also I mentioned later on that you could just remove this since it's unused)