I’ve been working on a wrapper for the Discord HTTP API. A lot of the IDs they use are uint64. It looks like this package should let me stop treating those IDs as strings and instead get some more type safety by converting them to uint64. (I know there’s folkertdev/int64 but it lacks a fromString function)
Currently fromString is missing from this package also, but it’s on my todo list. Simple implementation could be to just split string to two parts, use String.toInt on each, and combine results with multiplication.
Awesome package. I mentioned previously I have a few places I need to do 64-bit math, simply because some back-end endpoint outside of my control can give 64-bit values - this is really helpful.
Interesting. I have an application where I’d like a bit-identical std::mt19937_64, and while I had not looked seriously at the implementation options, I hadn’t’ considered there might be some pieces available. At this point it seems like my options are either implement myself in JS or Elm, or make a small server to run the C++ code.
Mersenne twister would certainly be an interesting benchmark for UInt64.
Looking at pseudo code, it would use and, xor, leftShiftBy, rightShiftZfBy, mul and modulo with 312 for 64-bit version.
These all are implemented for UInt64, if using divMod for modulo. Modulo can be made faster by implementing it separately from divMod, but I havn’t done that yet as I’m still considering use cases and how to implement div/mod without too much code duplication or overhead from function calls.
Basically I’m considering whether to duplicate code of divMod three times in divMod/div/mod, removing unneeded pieces from div and mod to make them faster for small values. (Each would still call divModFast if needed, so for large values there would be no difference in speed.)
EDIT: Actually Mersenne twister uses that modBy 312 only with small numbers, so it doesn’t use 64-bit modulo.
Sadly it doesn’t seem to be a perfect emulation of the g++ twister out of the box, so I’ll still need to figure out how to get that bit of code out of stdlib into a development environment where I can look at intermediate values in order to see where they diverge.