rust-random / book

The Rust Rand Book
Other
49 stars 19 forks source link

Document rationale for returning float types for a discrete distribution (Poisson) #34

Closed ndebuhr closed 3 years ago

ndebuhr commented 3 years ago

This PR expands the Poisson documentation:

https://github.com/rust-random/rand/issues/1093

vks commented 3 years ago

This is ready from my side, I'll merge it tomorrow so others have a chance to take a look.

dhardy commented 3 years ago

Correct casting is an under-appreciated problem in Rust, but at least as gets this right (or "good enough") now. I'm actually considering releasing a new library for this (see this code) since none of the current ones do what I want.

But this change looks fine to me :+1:

vks commented 3 years ago

@dhardy I have used the conv crate for this in the past, but it is no longer updated and has some issues.

dhardy commented 3 years ago

@vks Also not the same thing, especially convenient unwrap-by-default syntax. If you need a lot of conversions and the choice is x as y or y::conv_from(x).unwrap(), which are you likely to reach for? There's also num_traits and cast; the latter does at least try for convenient syntax, though perhaps not clear enough syntax.