Function vec_f64_into_vec_real

Source
pub fn vec_f64_into_vec_real<RealType: RealScalar>(
    vec: Vec<f64>,
) -> Vec<RealType>
Expand description

Converts the input vec of f64 values into a vector of floating point number, as described by the generic numerical kernel T.

§Panics

In debug and release mode a panic! will be emitted if the conversion from f64 to T::RealType causes some loss of information (e.g. if the type T has less precision of f64 then there is the possbility that some f64 values cannot be exactly represented by a T::RealType).

§Example

use num_valid::{Native64, vec_f64_into_vec_real};

// Conditional compilation for the `rug` feature
#[cfg(feature = "rug")]
use num_valid::RealRugStrictFinite;

// vector of f64 values
let a = vec![0., 1.];

let b: Vec<f64> = vec_f64_into_vec_real(a.clone());
assert_eq!(b[0], 0.);
assert_eq!(b[1], 1.);


// Conditional compilation for the `rug` feature
#[cfg(feature = "rug")]
{
    const PRECISION: u32 = 100;
    let b: Vec<RealRugStrictFinite<PRECISION>> = vec_f64_into_vec_real(a);
    assert_eq!(b[0].as_ref(), &rug::Float::with_val(PRECISION, 0.));
    assert_eq!(b[1].as_ref(), &rug::Float::with_val(PRECISION, 1.));
}