-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a Distribution<usize> for Poisson #958
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ pub trait Float: | |
/// Support converting to an unsigned integer. | ||
fn to_u64(self) -> Option<u64>; | ||
|
||
/// Support converting to an unsigned integer. | ||
fn to_usize(self) -> Option<usize>; | ||
|
||
/// Take the absolute value of self | ||
fn abs(self) -> Self; | ||
/// Take the largest integer less than or equal to self | ||
|
@@ -82,6 +85,15 @@ impl Float for f32 { | |
} | ||
} | ||
|
||
#[inline] | ||
fn to_usize(self) -> Option<usize> { | ||
if self >= 0. && self <= ::core::usize::MAX as f32 { | ||
Comment on lines
+89
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incorrect for 32-bit platforms. Check this out. This isn't your fault; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh this issue. I don't know how to solve this aswell. The link didn't suggest a solution. I think this belongs in another PR, or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes: #973 |
||
Some(self as usize) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
#[inline] | ||
fn abs(self) -> Self { | ||
self.abs() | ||
|
@@ -145,6 +157,14 @@ impl Float for f64 { | |
None | ||
} | ||
} | ||
#[inline] | ||
fn to_usize(self) -> Option<usize> { | ||
if self >= 0. && self <= ::core::usize::MAX as f64 { | ||
Some(self as usize) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
#[inline] | ||
fn abs(self) -> Self { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may panic on 32-bit platforms. Maybe we should document that somewhere?