3 ms·
This is exactly how random floats are computed in the Zig standard library: https://github.com/ziglang/zig/pull/10428/ https://github.com/ziglang/zig/pull/1042
by 10000truths 3y ago
This is exactly how random floats are computed in the Zig standard library:
https://github.com/ziglang/zig/pull/10428/ https://github.com/ziglang/zig/pull/10428/
- leiroigh 3y agoThis is awesome and the first precedent I've ever seen for a standard library doing the right thing on rand floats. Big kudos to the zig people and thanks for brightening my day!
- corsix 3y agoOh, cute. It looks like they ever-so-slightly overweight the probability of values whose mantissa is entirely zeroes though. For example, the probability of hitting exactly 0.5 should be 2^-54 + 2^-55, whereas zig looks to give it 2^-54 + 2^-54.