-
Notifications
You must be signed in to change notification settings - Fork 430
Closed
Milestone
Description
Abstract
Add the from_f32 and from_f64 constructors to the FloatMeasure, UnitMeasure & BoundedMeasure traits:
fn from_f32(val: f32) -> Self;
fn from_f64(val: f64) -> Self;Motivation
This will make it possible to construct assoiceated weight types inside generic algorithms, for example, by allowing to write something like:
if distance[ix(i)] + w + G::EdgeWeight::from_f32(0.1) < distance[ix(j)]Actually, such feature request was received in issue #723.
Details
- To get integer types from
floats, I suggest using the standardascast in implementations. - I suggest implementing exactly both methods for
f32andf64, so as not to lose flexibility in choosing between accuracy and memory consumption. - The
Measuretrait looks too general and in my opinion does not have to be a Real number semantically, so we should not implementfrom_f64andfrom_f32for it. - These changes are definitely breaking and can only be accepted in a major release (
0.8.0or further).
Progress
-
FlaotMeasure -
UnitMeasure -
BoundedMeasure