Skip to main content

to_f64

Function to_f64 

Source
pub fn to_f64(tensor: &Tensor) -> Result<Tensor>
Expand description

Convert an external Df64 tensor to an f64 tensor, low component included.

Rounding: the low component participates, so the result is the f64 nearest to hi + lo with the usual round-to-nearest, ties-to-even rule. This is not the truncation to hi that reinterpreting the payload would give.

Range: an infinite or NaN component propagates through the sum by IEEE arithmetic, and no range error is raised.

Allocation: a new f64 tensor with the same shape is allocated at the destination; the input payload is neither consumed nor modified.

§Errors

Returns tenferro_tensor::Error::UnsupportedDType when tensor is not an externally defined Df64 value.

§Examples

use tenferro_df64_proof::{conversion, Df64};
use tenferro_tensor::Tensor;
use tenferro_tensor::{DynRank, ErasedHostTensor, Host, TypedTensor};

let low = Df64 { hi: 1.0, lo: 2f64.powi(-52) };
let tensor = Tensor::external(ErasedHostTensor::new(
    TypedTensor::<_, DynRank, Host>::from_host_vec_col_major(vec![1], vec![low])?,
));

// The low component is part of the value, so it is part of the result.
assert_eq!(conversion::to_f64(&tensor)?.as_slice::<f64>()?, &[1.0 + 2f64.powi(-52)]);