-
-
Notifications
You must be signed in to change notification settings - Fork 473
Closed
Labels
B-APIBreakage: APIBreakage: API
Milestone
Description
Currently, Uniform::new
will panic on invalid parameters:
low >= high
(or>
fornew_inclusive
)- (float, debug only) non-finite
low
orhigh
- (float) non-finite
scale = high - low
Since #581 / #770, all other distributions with fallible constructor return a Result
instead of panic (I think).
For: consistency and utility (error checking in derived types)
Against: this is another significant breaking change, when we hope to be getting close to stable (though now is certainly better than later)
Alternative: try_new
, try_new_inclusive
constructors - but this is inconsistent and results in far too many methods.
Also related: Rng::gen_range
uses this. This should probably still panic on failure (note also Rng::fill
vs Rng::try_fill
; Rng::gen_bool
and Rng::gen_ratio
which may panic).
I suggest this error type:
enum Error {
/// Low > high, or equal in case of exclusive range
EmptyRange,
/// Input or range (high - low) is non-finite. Not relevant to integer types. In release mode only the range is checked.
NonFinite,
}
Link: #1165
SWW13
Metadata
Metadata
Assignees
Labels
B-APIBreakage: APIBreakage: API