Skip to content

Construct Measures from f32 & f64 #737

@starovoid

Description

@starovoid

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 standard as cast in implementations.
  • I suggest implementing exactly both methods for f32 and f64, so as not to lose flexibility in choosing between accuracy and memory consumption.
  • The Measure trait looks too general and in my opinion does not have to be a Real number semantically, so we should not implement from_f64 and from_f32 for it.
  • These changes are definitely breaking and can only be accepted in a major release (0.8.0 or further).

Progress

#733

  • FlaotMeasure
  • UnitMeasure
  • BoundedMeasure

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions