Skip to main content

csd/
lib.rs

1//! Canonical Signed Digit (CSD) conversion library.
2//!
3//! This library provides functions to convert between decimal numbers and
4//! Canonical Signed Digit (CSD) representation.
5//!
6//! # Features
7//!
8//! - `multiplier` (default): CSD multiplier module for Verilog code generation
9//! - `lcsre` (default): Longest common substring with repeated elements
10//! - `std` (optional): Logging support via env_logger
11//!
12//! # Quick Start
13//!
14//! ```rust
15//! use csd::{to_csd, to_decimal};
16//!
17//! // Convert decimal to CSD
18//! let csd = to_csd(28.5, 2);
19//! assert_eq!(csd, "+00-00.+0");
20//!
21//! // Convert CSD back to decimal
22//! let value = to_decimal("+00-00.+0");
23//! assert!((value - 28.5).abs() < 1e-10);
24//! ```
25
26pub mod csd;
27
28#[cfg(feature = "multiplier")]
29pub mod csd_multiplier;
30
31#[cfg(feature = "lcsre")]
32pub mod lcsre;
33
34pub use crate::csd::{
35    highest_power_of_two_in, to_csd, to_csd_i, to_csdnnz, to_csdnnz_i128, to_csdnnz_i64,
36    to_csdnnz_safe, to_decimal, to_decimal_fractional, to_decimal_fractional_safe, to_decimal_i,
37    to_decimal_i128_result, to_decimal_i64_result, to_decimal_i_result, to_decimal_integral_safe,
38    to_decimal_result, to_decimal_safe, validate_csd_format, CsdBuilder, CsdError, CsdResult,
39    RoundingStrategy,
40};
41
42#[cfg(feature = "multiplier")]
43pub use crate::csd_multiplier::{
44    generate_csd_multiplier, generate_csd_multipliers, CsdMultiplier, CsdMultiplierError,
45    MultiplierSpec,
46};
47
48#[cfg(feature = "lcsre")]
49pub use crate::lcsre::longest_repeated_substring;
50
51#[cfg(feature = "std")]
52pub mod logging;