oscbyspro / Ultimathnum

Binary arithmetic reimagined in Swift
Apache License 2.0
9 stars 1 forks source link

Recoverable random in infinite range #120

Open oscbyspro opened 1 month ago

oscbyspro commented 1 month ago

The range-based BinaryInteger.random(...) functions trap infinite ranges. It would be better to return nil. The current functions should be rewritten as unchecked conveniences with appropriate generic constraints.

oscbyspro commented 1 month ago

Hm. I suppose there are arguments in favor of keeping the trapping behavior. In particular, picking a random value in an infinite range a lot like multiplying an arbitrary integer until you run out of memory. It isn't undefined. You just run out of memory, or at least that's what the trapping behavior emulates. It might be best to keep overallocation handling, or lack thereof, consistent across the board.