### Rust Documentation Links Source: https://docs.rs/fixnum/latest/src/fixnum/schemars Provides links to various Rust programming language resources, including the official website, The Book, standard library API reference, Rust by Example, and the Cargo Guide. ```Rust Rust Resources: - Rust website: https://www.rust-lang.org/ - The Book: https://doc.rust-lang.org/book/ - Standard Library API Reference: https://doc.rust-lang.org/std/ - Rust by Example: https://doc.rust-lang.org/rust-by-example/ - The Cargo Guide: https://doc.rust-lang.org/cargo/guide/ - Clippy Documentation: https://doc.rust-lang.org/nightly/clippy ``` -------------------------------- ### fixnum Module Documentation Source: https://docs.rs/fixnum/latest/fixnum/index Documentation for the main `fixnum` module, covering its features, examples, available operations, and implementation details for wrapper types. ```Rust Module: fixnum Features: - (list of features) Example: - (example usage) Available operations: - (list of operations) Implementing wrapper types: - Details on how to implement wrapper types for fixnum. ``` -------------------------------- ### Rust FixedPoint rsqrt Example Source: https://docs.rs/fixnum/latest/fixnum/struct Example demonstrating the usage of the rsqrt method for FixedPoint numbers in Rust, including handling of positive and negative inputs and different rounding modes. ```rust use fixnum::{ArithmeticError, FixedPoint, typenum::U9}; use fixnum::ops::{Zero, RoundMode::*}; type Amount = FixedPoint; let a: Amount = "81".parse()?; let b: Amount = "2".parse()?; let c: Amount = "-100".parse()?; assert_eq!(a.rsqrt(Floor)?, "9".parse()?); assert_eq!(b.rsqrt(Floor)?, "1.414213562".parse()?); assert_eq!(b.rsqrt(Ceil)?, "1.414213563".parse()?); assert_eq!(c.rsqrt(Floor), Err(ArithmeticError::DomainViolation)); ``` -------------------------------- ### Rust Fixed-Point Number Example Source: https://docs.rs/fixnum/latest/fixnum/index Demonstrates the usage of the `FixedPoint` type from the `fixnum` crate for fixed-point arithmetic. It shows how to define a fixed-point type with a specific precision and perform operations like addition and multiplication with different rounding modes. ```Rust use fixnum::{FixedPoint, typenum::U9, ops::*, fixnum}; /// Signed fixed point amount over 64 bits, 9 decimal places. /// /// MAX = (2 ^ (BITS_COUNT - 1) - 1) / 10 ^ PRECISION = /// = (2 ^ (64 - 1) - 1) / 1e9 = /// = 9223372036.854775807 ~ 9.2e9 /// ERROR_MAX = 0.5 / (10 ^ PRECISION) = /// = 0.5 / 1e9 = /// = 5e-10 type Amount = FixedPoint; let a: Amount = fixnum!(0.1, 9); let b: Amount = fixnum!(0.2, 9); assert_eq!(a.cadd(b)?, fixnum!(0.3, 9)); let expences: Amount = fixnum!(0.000000001, 9); // 1e-9 * (Floor) 1e-9 = 0 assert_eq!(expences.rmul(expences, RoundMode::Floor)?, fixnum!(0, 9)); // 1e-9 * (Ceil) 1e-9 = 1e-9 assert_eq!(expences.rmul(expences, RoundMode::Ceil)?, expences); ``` -------------------------------- ### FixedPoint rsqrt Example Source: https://docs.rs/fixnum/latest/fixnum/struct Example usage of the rsqrt method for FixedPoint numbers, demonstrating its behavior with positive and negative inputs, and different rounding modes. ```rust use fixnum::{ArithmeticError, FixedPoint, typenum::U9}; use fixnum::ops::{Zero, RoundMode::*}; type Amount = FixedPoint; let a: Amount = "81".parse()?; let b: Amount = "2".parse()?; let c: Amount = "-100".parse()?; assert_eq!(a.rsqrt(Floor)?, "9".parse()?); assert_eq!(b.rsqrt(Floor)?, "1.414213562".parse()?); assert_eq!(b.rsqrt(Ceil)?, "1.414213563".parse()?); assert_eq!(c.rsqrt(Floor), Err(ArithmeticError::DomainViolation)); ``` -------------------------------- ### Fixnum Saturating Addition Example Source: https://docs.rs/fixnum/latest/src/fixnum/ops/mod Demonstrates the usage of saturating addition for FixedPoint numbers in Rust. It shows how addition results in MAX or MIN values upon overflow. ```rust # #[cfg(feature = "i64")] # fn main() -> Result<(), Box> { use fixnum::{FixedPoint, typenum::U9, ops::{Bounded, RoundMode::*, CheckedAdd}}; type Amount = FixedPoint; let a: Amount = "1000.00002".parse()?; let b: Amount = "9222000000".parse()?; let c: Amount = "9222001000.00002".parse()?; // 1000.00002 + 9222000000 = 9222001000.00002 assert_eq!(a.saturating_add(b), c); // 9222000000 + 9222000000 = MAX assert_eq!(c.saturating_add(c), Amount::MAX); let d: Amount = "-9222000000".parse()?; // -9222000000 + (-9222000000) = MIN assert_eq!(d.saturating_add(d), Amount::MIN); # Ok(()) } # #[cfg(not(feature = "i64"))] # fn main() {} ``` -------------------------------- ### fixnum Example Usage Source: https://docs.rs/fixnum/latest/src/fixnum/lib This Rust code example demonstrates the basic usage of the fixnum crate, specifically focusing on arithmetic operations and rounding. It defines a custom fixed-point type `Amount` with 64-bit integers and 9 decimal places, then performs addition and multiplication with different rounding modes. ```Rust # #[cfg(feature = "i64")] # fn main() -> Result<(), Box> { use fixnum::{FixedPoint, typenum::U9, ops::*, fixnum}; /// Signed fixed point amount over 64 bits, 9 decimal places. /// /// MAX = (2 ^ (BITS_COUNT - 1) - 1) / 10 ^ PRECISION = /// = (2 ^ (64 - 1) - 1) / 1e9 = /// = 9223372036.854775807 ~ 9.2e9 /// ERROR_MAX = 0.5 / (10 ^ PRECISION) = /// = 0.5 / 1e9 = /// = 5e-10 type Amount = FixedPoint; let a: Amount = fixnum!(0.1, 9); let b: Amount = fixnum!(0.2, 9); assert_eq!(a.cadd(b)?, fixnum!(0.3, 9)); let expences: Amount = fixnum!(0.000000001, 9); // 1e-9 * (Floor) 1e-9 = 0 assert_eq!(expences.rmul(expences, RoundMode::Floor)?, fixnum!(0, 9)); // 1e-9 * (Ceil) 1e-9 = 1e-9 assert_eq!(expences.rmul(expences, RoundMode::Ceil)?, expences); # Ok(()) } ``` -------------------------------- ### FixedPoint Integral Calculation Example Source: https://docs.rs/fixnum/latest/fixnum/struct An example demonstrating the usage of the 'integral' method with different RoundMode options (Floor, Nearest, Ceil) for both positive and negative numbers. ```Rust use fixnum::{FixedPoint, typenum::U9, ops::RoundMode::*}; type Amount = FixedPoint; let a: Amount = "8273.519".parse()?; assert_eq!(a.integral(Floor), 8273); assert_eq!(a.integral(Nearest), 8274); assert_eq!(a.integral(Ceil), 8274); let a: Amount = "-8273.519".parse()?; assert_eq!(a.integral(Floor), -8274); assert_eq!(a.integral(Nearest), -8274); assert_eq!(a.integral(Ceil), -8273); ``` -------------------------------- ### Fixnum Macro Usage Example Source: https://docs.rs/fixnum/latest/src/fixnum/macros This snippet demonstrates how to use the `fixnum!` macro to create a fixed-point number. It shows defining a type alias for a currency with 9 decimal places and then using the `fp!` macro (a wrapper around `fixnum!`) to instantiate a value. ```rust use fixnum::{FixedPoint, typenum::U9}; type Currency = FixedPoint; macro_rules! fp { ($val:literal) => { fixnum::fixnum!($val, 9); }; } # fn main() -> Result<(), Box> { let c: Currency = fp!(12.34); # Ok(()) } ``` -------------------------------- ### Rust FixedPoint Example with Rounding Source: https://docs.rs/fixnum/latest/fixnum Demonstrates the usage of the `FixedPoint` type from the `fixnum` crate for fixed-point arithmetic. It shows how to define a fixed-point number with a specific precision (9 decimal places) and perform addition and multiplication with different rounding modes (Floor, Ceil). ```Rust use fixnum::{FixedPoint, typenum::U9, ops::*, fixnum}; /// Signed fixed point amount over 64 bits, 9 decimal places. /// /// MAX = (2 ^ (BITS_COUNT - 1) - 1) / 10 ^ PRECISION = /// = (2 ^ (64 - 1) - 1) / 1e9 = /// = 9223372036.854775807 ~ 9.2e9 /// ERROR_MAX = 0.5 / (10 ^ PRECISION) = /// = 0.5 / 1e9 = /// = 5e-10 type Amount = FixedPoint; let a: Amount = fixnum!(0.1, 9); let b: Amount = fixnum!(0.2, 9); assert_eq!(a.cadd(b)?, fixnum!(0.3, 9)); let expences: Amount = fixnum!(0.000000001, 9); // 1e-9 * (Floor) 1e-9 = 0 assert_eq!(expences.rmul(expences, RoundMode::Floor)?, fixnum!(0, 9)); // 1e-9 * (Ceil) 1e-9 = 1e-9 assert_eq!(expences.rmul(expences, RoundMode::Ceil)?, expences); ``` -------------------------------- ### fixnum crate overview Source: https://docs.rs/fixnum/latest/fixnum/serde/repr_option/index Provides an overview of the fixnum crate, including its version, license, source code links, and dependencies. It also indicates the documentation coverage percentage. ```Rust fixnum 0.9.3 License: MIT OR Apache-2.0 Dependencies: i256 = 0.1.1 itoa = ^1.0.1 parity-scale-codec = ^3 (optional) schemars = ^0.8 (optional) serde = ^1.0 (optional) static_assertions = 1.1.0 typenum = ^1.12.0 Dev Dependencies: anyhow = ^1.0.38 colored = ^2.0.0 criterion = ^0.5 derive_more = ^1.0.0 proptest = ^1.0.0 quick-xml = ^0.24.0 rust_decimal = ^1.22.0 serde = ^1.0 serde_json = ^1 trybuild = ^1.0.85 100% of the crate is documented. ``` -------------------------------- ### fixnum crate overview Source: https://docs.rs/fixnum/latest/fixnum/serde/repr/fn Overview of the fixnum crate, including its version, license, source code links, and dependencies. It highlights that 100% of the crate is documented. ```Rust Project: /websites/rs_fixnum Dependencies: * i256 =0.1.1 * itoa ^1.0.1 * parity-scale-codec ^3 * schemars ^0.8 * serde ^1.0 * static_assertions ^1.1.0 * typenum ^1.12.0 Dev Dependencies: * anyhow ^1.0.38 * colored ^2.0.0 * criterion ^0.5 * derive_more ^1.0.0 * proptest ^1.0.0 * quick-xml ^0.24.0 * rust_decimal ^1.22.0 * serde ^1.0 * serde_json ^1 * trybuild ^1.0.85 License: MIT OR Apache-2.0 Documentation: 100% of the crate is documented. ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/serde Provides an overview of the fixnum Rust crate, including its version, license, source code links, and dependencies. It also indicates the documentation coverage percentage. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Source: https://github.com/loyd/fixnum Dependencies: - i256 =0.1.1 - itoa =^1.0.1 - parity-scale-codec =^3 (optional) - schemars =^0.8 (optional) - serde =^1.0 (optional) - static_assertions =1.1.0 - typenum =^1.12.0 Dev Dependencies: - anyhow =^1.0.38 - colored =^2.0.0 - criterion =^0.5 - derive_more =^1.0.0 - proptest =^1.0.0 - quick-xml =^0.24.0 - rust_decimal =^1.22.0 - serde =^1.0 - serde_json =^1 - trybuild =^1.0.85 Documentation Coverage: 100% ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/const_fn Provides an overview of the fixnum crate, including its version, license, source code links, and dependencies. It highlights that 100% of the crate is documented. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Description: Fixed-point numbers with explicit rounding Source: https://github.com/loyd/fixnum Dependencies: - i256 =0.1.1 - itoa =^1.0.1 - parity-scale-codec =^3 - schemars =^0.8 - serde =^1.0 - static_assertions =^1.1.0 - typenum =^1.12.0 Dev Dependencies: - anyhow =^1.0.38 - colored =^2.0.0 - criterion =^0.5 - derive_more =^1.0.0 - proptest =^1.0.0 - quick-xml =^0.24.0 - rust_decimal =^1.22.0 - serde =^1.0 - serde_json =^1 - trybuild =^1.0.85 Documentation: 100% documented ``` -------------------------------- ### Fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/schemars Provides an overview of the fixnum crate, including its version, license, source code repository, and dependencies. It also lists supported platforms and feature flags. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Repository: https://github.com/loyd/fixnum Dependencies: - i256 ^0.1.1 - itoa ^1.0.1 - parity-scale-codec ^3 - schemars ^0.8 - serde ^1.0 - static_assertions ^1.1.0 - typenum ^1.12.0 Supported Platforms: - i686-pc-windows-msvc - i686-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-msvc - x86_64-unknown-linux-gnu Feature Flags: Browse available feature flags of fixnum-0.9.3 ``` -------------------------------- ### fixnum Crate Sections Source: https://docs.rs/fixnum/latest/fixnum Key sections within the fixnum crate documentation, highlighting features, examples, and implementation details. ```Rust fixnum Crate Documentation Sections: - fixnum: Main module, includes features, examples, available operations, and implementing wrapper types. ``` -------------------------------- ### Fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/string Provides an overview of the fixnum crate, including its version, license, source code repository, and dependencies. It also lists supported platforms and available feature flags. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Source: https://github.com/loyd/fixnum Dependencies: - i256 ^0.1.1 - itoa ^1.0.1 - parity-scale-codec ^3 (optional) - schemars ^0.8 (optional) - serde ^1.0 (optional) - static_assertions ^1.1.0 - typenum ^1.12.0 Platforms: - i686-pc-windows-msvc - i686-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-msvc - x86_64-unknown-linux-gnu Documentation: 100% documented ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/macros Provides an overview of the fixnum crate, including its version, license, source code links, and dependencies. It also indicates the documentation coverage percentage. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Source: https://github.com/loyd/fixnum Dependencies: - i256 (^0.1.1) - itoa (^1.0.1) - parity-scale-codec (^3) - schemars (^0.8) - serde (^1.0) - static_assertions (^1.1.0) - typenum (^1.12.0) Dev Dependencies: - anyhow (^1.0.38) - colored (^2.0.0) - criterion (^0.5) - derive_more (^1.0.0) - proptest (^1.0.0) - quick-xml (^0.24.0) - rust_decimal (^1.22.0) - serde (^1.0) - serde_json (^1) - trybuild (^1.0.85) Documentation Coverage: 100% ``` -------------------------------- ### fixnum Crate Sections Source: https://docs.rs/fixnum/latest/index Key sections within the fixnum crate documentation, highlighting features, examples, and implementation details. ```Rust fixnum Crate Documentation Sections: - fixnum: Main module, includes features, examples, available operations, and implementing wrapper types. ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/i256_polyfill This snippet provides an overview of the fixnum crate, including its version, license, source code links, and dependencies. It highlights that 100% of the crate is documented. ```Rust Project: /websites/rs_fixnum fixnum 0.9.3 License: MIT OR Apache-2.0 Dependencies: - i256 =0.1.1 - itoa =^1.0.1 - parity-scale-codec =^3 - schemars =^0.8 - serde =^1.0 - static_assertions =^1.1.0 - typenum =^1.12.0 100% of the crate is documented. ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/parity Provides an overview of the fixnum crate, including its version, license, source code links, and dependencies. It also indicates the documentation coverage percentage. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Source: https://github.com/loyd/fixnum Dependencies: - i256 =0.1.1 - itoa ^1.0.1 - parity-scale-codec ^3 - schemars ^0.8 - serde ^1.0 - static_assertions ^1.1.0 - typenum ^1.12.0 Documentation Coverage: 100% ``` -------------------------------- ### Rust ArithmeticError Enum Source: https://docs.rs/fixnum/latest/src/fixnum/errors Defines possible errors during arithmetic operations, including Overflow, DivisionByZero, and DomainViolation. It provides a method to get a static string representation of each error. ```rust pub enum ArithmeticError { /// A result cannot be represented. Overflow, /// Try to divide by zero. DivisionByZero, /// When someone tries to use operand out of the set of departure of the function. /// E.g.: when you try to compute the square root of a negative number. DomainViolation, } impl ArithmeticError { /// Stringify an error. pub const fn as_str(&self) -> &'static str { match self { Self::Overflow => "overflow", Self::DivisionByZero => "division by zero", Self::DomainViolation => "domain violation", } } } ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/ops/sqrt Provides an overview of the fixnum crate, including its version, license, source code links, owners, dependencies, and documentation status. It also lists supported platforms. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Description: Fixed-point numbers with explicit rounding Source: https://github.com/loyd/fixnum Documentation: https://docs.rs/fixnum/latest Dependencies: - i256 =0.1.1 - itoa =^1.0.1 - parity-scale-codec =^3 - schemars =^0.8 - serde =^1.0 - static_assertions =^1.1.0 - typenum =^1.12.0 Dev Dependencies: - anyhow =^1.0.38 - colored =^2.0.0 - criterion =^0.5 - derive_more =^1.0.0 - proptest =^1.0.0 - quick-xml =^0.24.0 - rust_decimal =^1.22.0 - serde =^1.0 - serde_json =^1 - trybuild =^1.0.85 Platforms: - i686-pc-windows-msvc - i686-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-msvc - x86_64-unknown-linux-gnu) Documentation Coverage: 100% ``` -------------------------------- ### Rust: Integral Part Extraction Source: https://docs.rs/fixnum/latest/src/fixnum/lib Extracts the integral part of a fixed-point number using a specified rounding mode (Floor, Nearest, Ceil). Includes examples for positive and negative numbers. ```Rust pub fn integral(self, mode: RoundMode) -> $layout { // ... implementation details ... } ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/fixnum/index Provides an overview of the fixnum Rust crate, including its version, license, source code links, and dependencies. It also lists supported platforms and feature flags. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Source: https://github.com/loyd/fixnum Dependencies: - i256 =0.1.1 - itoa =^1.0.1 - parity-scale-codec =^3 - schemars =^0.8 - serde =^1.0 - static_assertions =^1.1.0 - typenum =^1.12.0 Dev Dependencies: - anyhow =^1.0.38 - colored =^2.0.0 - criterion =^0.5 - derive_more =^1.0.0 - proptest =^1.0.0 - quick-xml =^0.24.0 - rust_decimal =^1.22.0 - serde =^1.0 - serde_json =^1 - trybuild =^1.0.85 Platforms: - i686-pc-windows-msvc - i686-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-msvc - x86_64-unknown-linux-gnu Features: - (list of features) ``` -------------------------------- ### Fixnum Power Table Data Source: https://docs.rs/fixnum/latest/src/fixnum/power_table This snippet displays a portion of the power table from the fixnum project. It lists powers of 2, starting from 2^77 down to 2^114, along with their corresponding exponents. ```rust /* 77 | 1125899906842624 */ 16, /* 78 | 562949953421312 */ 15, /* 79 | 281474976710656 */ 15, /* 80 | 140737488355328 */ 15, /* 81 | 70368744177664 */ 14, /* 82 | 35184372088832 */ 14, /* 83 | 17592186044416 */ 14, /* 84 | 8796093022208 */ 13, /* 85 | 4398046511104 */ 13, /* 86 | 2199023255552 */ 13, /* 87 | 1099511627776 */ 13, /* 88 | 549755813888 */ 12, /* 89 | 274877906944 */ 12, /* 90 | 137438953472 */ 12, /* 91 | 68719476736 */ 11, /* 92 | 34359738368 */ 11, /* 93 | 17179869184 */ 11, /* 94 | 8589934592 */ 10, /* 95 | 4294967296 */ 10, /* 96 | 2147483648 */ 10, /* 97 | 1073741824 */ 10, /* 98 | 536870912 */ 9, /* 99 | 268435456 */ 9, /* 100 | 134217728 */ 9, /* 101 | 67108864 */ 8, /* 102 | 33554432 */ 8, /* 103 | 16777216 */ 8, /* 104 | 8388608 */ 7, /* 105 | 4194304 */ 7, /* 106 | 2097152 */ 7, /* 107 | 1048576 */ 7, /* 108 | 524288 */ 6, /* 109 | 262144 */ 6, /* 110 | 131072 */ 6, /* 111 | 65536 */ 5, /* 112 | 32768 */ 5, /* 113 | 16384 */ 5, /* 114 | 8192 */ 4 ``` -------------------------------- ### fixnum Dependencies Source: https://docs.rs/fixnum/latest/fixnum/serde/str/fn Lists the normal and development dependencies for the fixnum crate version 0.9.3. This includes crates like i256, itoa, serde, and testing utilities. ```Rust Dependencies: i256 = "0.1.1" itoa = "^1.0.1" static_assertions = "^1.1.0" typenum = "^1.12.0" Optional Dependencies: parity-scale-codec = "^3" schemars = "^0.8" serde = "^1.0" Dev Dependencies: anyhow = "^1.0.38" colored = "^2.0.0" criterion = "^0.5" derive_more = "^1.0.0" proptest = "^1.0.0" quick-xml = "^0.24.0" rust_decimal = "^1.22.0" serde = "^1.0" serde_json = "^1" trybuild = "^1.0.85" ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/fixnum/serde/str/fn Overview of the fixnum crate, version 0.9.3. Includes links to the crate on docs.rs and crates.io, license information (MIT or Apache-2.0), and source code browsing. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Source: https://github.com/loyd/fixnum Docs: https://docs.rs/fixnum/latest/fixnum/ ``` -------------------------------- ### Fixnum Data Structures and Operations Source: https://docs.rs/fixnum/latest/src/fixnum/lib Defines fixed-point number types (Price, PriceDelta, Amount, Ratio) and implements arithmetic operations using macros and traits. Includes examples of usage for multiplication. ```Rust //! struct Price(Fp64); //! #[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, From)] //! struct PriceDelta(Fp64); //! #[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, From)] //! struct Amount(Fp64); //! #[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, From)] //! struct Ratio(Fp64); //! //! impl_op!(Size [cadd] Size = Size); //! impl_op!(Size [csub] Size = Size); //! impl_op!(Size [rdiv] Size = Ratio); //! impl_op!(Size [cmul] Price = Amount); //! impl_op!(Price [csub] Price = PriceDelta); //! impl_op!(Price [cadd] PriceDelta = Price); //! impl_op!(Price [rdiv] Price = Ratio); //! impl_op!(Price [rmul] Ratio = Price); //! impl_op!(PriceDelta [cadd] PriceDelta = PriceDelta); //! impl_op!(Amount [cadd] Amount = Amount); //! impl_op!(Amount [csub] Amount = Amount); //! //! // Use it. //! use fixnum::ops::*; //! let size = Size(4); //! let price = fixnum!(4.25, 9); // compile-time //! let amount = size.cmul(price)?; //! assert_eq!(amount, fixnum!(17, 9)); ``` -------------------------------- ### Fixnum Checked Subtraction (csub) Source: https://docs.rs/fixnum/latest/src/fixnum/ops/mod Demonstrates the checked subtraction operation for Fixnum types. It performs subtraction and returns an error if overflow occurs. This example uses i64 with U9 precision. ```rust # #[cfg(feature = "i64")] # fn main() -> Result<(), Box> { use fixnum::{FixedPoint, typenum::U9, ops::CheckedSub}; type Amount = FixedPoint; let a: Amount = "0.3".parse()?; let b: Amount = "0.1".parse()?; let c: Amount = "0.2".parse()?; assert_eq!(a.csub(b)?, c); # Ok(()) } # #[cfg(not(feature = "i64"))] # fn main() {} ``` -------------------------------- ### fixnum platform support Source: https://docs.rs/fixnum/latest/fixnum/serde/repr/fn Lists the platforms for which the fixnum crate has been tested and provides links to platform-specific documentation redirects. ```Rust Platform Support: * i686-pc-windows-msvc * i686-unknown-linux-gnu * x86_64-apple-darwin * x86_64-pc-windows-msvc * x86_64-unknown-linux-gnu ``` -------------------------------- ### fixnum crate overview Source: https://docs.rs/fixnum/latest/src/fixnum/power_table Provides an overview of the fixnum crate, including its version, license, source code links, and dependencies. It also indicates the documentation coverage percentage. ```Rust fixnum 0.9.3 MIT OR Apache-2.0 Dependencies: i256 =0.1.1 itoa ^1.0.1 parity-scale-codec ^3 schemars ^0.8 serde ^1.0 static_assertions ^1.1.0 typenum ^1.12.0 anyhow ^1.0.38 (dev) colored ^2.0.0 (dev) criterion ^0.5 (dev) derive_more ^1.0.0 (dev) proptest ^1.0.0 (dev) quick-xml ^0.24.0 (dev) rust_decimal ^1.22.0 (dev) serde ^1.0 (dev) serde_json ^1 (dev) trybuild ^1.0.85 (dev) 100% of the crate is documented ``` -------------------------------- ### Fixnum Wrapper Types Source: https://docs.rs/fixnum/latest/src/fixnum/lib Demonstrates the use of wrapper types with the `fixnum!` macro to restrict the domain of FixedPoint numbers, reducing the chance of mistakes. Includes an example of defining a `Fp64` type and a `Size` wrapper. ```Rust use derive_more::From; use fixnum::{impl_op, typenum::U9, FixedPoint, fixnum}; type Fp64 = FixedPoint; #[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, From)] struct Size(i32); // Example usage with fixnum! macro (not shown in provided snippet but implied) // let fp_val = fixnum!(1.234: Fp64); // let size_val = Size::from(10); ``` -------------------------------- ### Rust FixedPoint Example Source: https://docs.rs/fixnum/latest/index Demonstrates the usage of the `FixedPoint` struct from the `fixnum` crate for arithmetic operations with explicit rounding. It defines a type alias `Amount` for a fixed-point number with 64 bits and 9 decimal places. ```Rust use fixnum::{FixedPoint, typenum::U9, ops::*, fixnum}; /// Signed fixed point amount over 64 bits, 9 decimal places. /// /// MAX = (2 ^ (BITS_COUNT - 1) - 1) / 10 ^ PRECISION = /// = (2 ^ (64 - 1) - 1) / 1e9 = /// = 9223372036.854775807 ~ 9.2e9 /// ERROR_MAX = 0.5 / (10 ^ PRECISION) = /// = 0.5 / 1e9 = /// = 5e-10 type Amount = FixedPoint; let a: Amount = fixnum!(0.1, 9); let b: Amount = fixnum!(0.2, 9); assert_eq!(a.cadd(b)?, fixnum!(0.3, 9)); let expences: Amount = fixnum!(0.000000001, 9); // 1e-9 * (Floor) 1e-9 = 0 assert_eq!(expences.rmul(expences, RoundMode::Floor)?, fixnum!(0, 9)); // 1e-9 * (Ceil) 1e-9 = 1e-9 assert_eq!(expences.rmul(expences, RoundMode::Ceil)?, expences); ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/fixnum/macro Provides an overview of the fixnum Rust crate, including its version, license, dependencies, and links to external resources. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Dependencies: - i256 =0.1.1 - itoa ^1.0.1 - parity-scale-codec ^3 - schemars ^0.8 - serde ^1.0 - static_assertions ^1.1.0 - typenum ^1.12.0 - anyhow ^1.0.38 (dev) - colored ^2.0.0 (dev) - criterion ^0.5 (dev) - derive_more ^1.0.0 (dev) - proptest ^1.0.0 (dev) - quick-xml ^0.24.0 (dev) - rust_decimal ^1.22.0 (dev) - serde ^1.0 (dev) - serde_json ^1 (dev) - trybuild ^1.0.85 (dev) Documentation: 100% complete Source: https://github.com/loyd/fixnum Crates.io: https://crates.io/crates/fixnum Docs.rs: https://docs.rs/fixnum/latest/fixnum/ ``` -------------------------------- ### FixedPoint JSON Schema Generation Source: https://docs.rs/fixnum/latest/fixnum/struct Provides methods for generating JSON schemas for the FixedPoint type. Includes functions to determine if schemas should be referenceable, get the schema name, generate the schema itself, and provide a unique schema ID. ```rust fn is_referenceable() -> bool // Whether JSON Schemas generated for this type should be re-used where possible using the `$ref` keyword. fn schema_name() -> String // The name of the generated JSON Schema. fn json_schema(_: &mut SchemaGenerator) -> Schema // Generates a JSON Schema for this type. fn schema_id() -> Cow<'static, str> // Returns a string that uniquely identifies the schema produced by this type. ``` -------------------------------- ### fixnum Crate Overview Source: https://docs.rs/fixnum/latest/src/fixnum/errors Provides an overview of the fixnum crate, including its version, license, source code links, and dependencies. It also lists supported platforms and feature flags. ```Rust Crate: fixnum Version: 0.9.3 License: MIT OR Apache-2.0 Source: https://github.com/loyd/fixnum Dependencies: - i256 =0.1.1 - itoa ^1.0.1 - parity-scale-codec ^3 - schemars ^0.8 - serde ^1.0 - static_assertions ^1.1.0 - typenum ^1.12.0 Platforms: - i686-pc-windows-msvc - i686-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-msvc - x86_64-unknown-linux-gnu Documentation: 100% complete ``` -------------------------------- ### Saturating Rounded Multiplication Example Source: https://docs.rs/fixnum/latest/src/fixnum/ops/mod Demonstrates the usage of saturating_rmul for fixed-point numbers with different rounding modes (Ceil and Floor). It shows how multiplication results are clamped to the type's minimum or maximum bounds when overflow occurs. ```rust use fixnum::{FixedPoint, typenum::U9, ops::{Zero, Bounded, RoundMode::*, RoundingMul}}; type Amount = FixedPoint; let a: Amount = "0.000000001".parse()?; let b: Amount = "0.000000002".parse()?; // 1e-9 * (SaturatingCeil) 2e9 = 1e-9 assert_eq!(a.saturating_rmul(b, Ceil), a); // 1e-9 * (SaturatingFloor) 2e9 = 0 assert_eq!(a.saturating_rmul(b, Floor), Amount::ZERO); // MIN * (SaturatingFloor) MIN = MAX assert_eq!(Amount::MIN.saturating_rmul(Amount::MIN, Floor), Amount::MAX); let c: Amount = "-1.000000001".parse()?; // -1.000000001 * (SaturatingCeil) MAX = MIN assert_eq!(c.saturating_rmul(Amount::MAX, Ceil), Amount::MIN); ``` -------------------------------- ### fixnum crate platform support Source: https://docs.rs/fixnum/latest/fixnum/serde/repr/index Details the platforms for which the fixnum crate has been built and tested. Supported platforms include various Windows, Linux, and macOS configurations. ```Rust Platform: * [i686-pc-windows-msvc] * [i686-unknown-linux-gnu] * [x86_64-apple-darwin] * [x86_64-pc-windows-msvc] * [x86_64-unknown-linux-gnu] ``` -------------------------------- ### Fixnum Saturating Subtraction (saturating_sub) Source: https://docs.rs/fixnum/latest/src/fixnum/ops/mod Illustrates the saturating subtraction operation for Fixnum types. This method subtracts two numbers, clamping the result to the minimum or maximum representable value if overflow occurs. The example uses i64 with U9 precision. ```rust # #[cfg(feature = "i64")] # fn main() -> Result<(), Box> { use fixnum::{FixedPoint, typenum::U9, ops::{Bounded, RoundMode::*, CheckedSub}}; type Amount = FixedPoint; let a: Amount = "9222001000.00002".parse()?; let b: Amount = "9222000000".parse()?; let c: Amount = "1000.00002".parse()?; // 9222001000.00002 - 9222000000 = 1000.00002 assert_eq!(a.saturating_sub(b), c); let d: Amount = "-9222000000".parse()?; // 9222000000 - (-9222000000) = MAX assert_eq!(b.saturating_sub(d), Amount::MAX); // -9222000000 - 9222000000 = MIN assert_eq!(d.saturating_sub(b), Amount::MIN); # Ok(()) } # #[cfg(not(feature = "i64"))] # fn main() {} ``` -------------------------------- ### fixnum crate dependencies Source: https://docs.rs/fixnum/latest/fixnum/serde/str_option/index Lists the normal and development dependencies for the fixnum crate version 0.9.3. Dependencies include crates like i256, itoa, parity-scale-codec, schemars, serde, static_assertions, typenum, anyhow, colored, criterion, derive_more, proptest, quick-xml, rust_decimal, serde_json, and trybuild. ```Rust Dependencies: * [ i256 =0.1.1 _normal_ _optional_ ] * [ itoa ^1.0.1 _normal_ ] * [ parity-scale-codec ^3 _normal_ _optional_ ] * [ schemars ^0.8 _normal_ _optional_ ] * [ serde ^1.0 _normal_ _optional_ ] * [ static_assertions ^1.1.0 _normal_ ] * [ typenum ^1.12.0 _normal_ ] * [ anyhow ^1.0.38 _dev_ ] * [ colored ^2.0.0 _dev_ ] * [ criterion ^0.5 _dev_ ] * [ derive_more ^1.0.0 _dev_ ] * [ proptest ^1.0.0 _dev_ ] * [ quick-xml ^0.24.0 _dev_ ] * [ rust_decimal ^1.22.0 _dev_ ] * [ serde ^1.0 _dev_ ] * [ serde_json ^1 _dev_ ] * [ trybuild ^1.0.85 _dev_ ] ``` -------------------------------- ### fixnum crate platform support Source: https://docs.rs/fixnum/latest/fixnum/serde/str_option/index Details the platforms for which the fixnum crate has been built and tested. Supported platforms include various configurations of Windows (msvc) and Linux (gnu), as well as macOS. ```Rust Platform: * [i686-pc-windows-msvc] * [i686-unknown-linux-gnu] * [x86_64-apple-darwin] * [x86_64-pc-windows-msvc] * [x86_64-unknown-linux-gnu] ```