pub fn to_csdnnz(decimal_value: f64, nnz: u32) -> StringExpand description
Convert to CSD representation approximately with fixed number of non-zero
The to_csdnnz function converts a given number into a CSD (Canonic Signed Digit) representation
approximately with a specified number of non-zero digits. This version limits the number of
non-zero digits in the output representation.
Arguments:
decimal_value: Thedecimal_valueparameter is a double precision floating-point number that represents the input value for conversion to CSD (Canonic Signed Digit) fixed-point representation.nnz: The parameternnzstands for “number of non-zero bits”. It represents the maximum number of non-zero bits allowed in the output CSD (Canonical Signed Digit) representation of the givendecimal_value.
Returns:
The function to_csdnnz returns a string representation of the given decimal_value in Canonical Signed
Digit (CSD) format.
§Examples
use csd::csd::to_csdnnz;
let s1 = to_csdnnz(28.5, 4);
let s2 = to_csdnnz(-0.5, 4);
assert_eq!(to_csdnnz(28.5, 4), "+00-00.+".to_string());
assert_eq!(to_csdnnz(-0.5, 4), "0.-".to_string());
assert_eq!(to_csdnnz(0.0, 4), "0".to_string());
assert_eq!(to_csdnnz(0.0, 0), "0".to_string());
assert_eq!(to_csdnnz(0.5, 4), "0.+".to_string());
assert_eq!(to_csdnnz(-0.5, 4), "0.-".to_string());
assert_eq!(to_csdnnz(28.5, 2), "+00-00".to_string());
assert_eq!(to_csdnnz(28.5, 1), "+00000".to_string());