{"record":{"id":"72d7c104636bcabf","repo":"nautechsystems/nautilus_trader","slug":"fractional-raw-quantity-must-fit-in-decimal","errorCode":null,"errorMessage":"Fractional raw quantity must fit in Decimal","messagePattern":"Fractional raw quantity must fit in Decimal","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/model/src/types/quantity.rs","lineNumber":445,"sourceCode":"        #[allow(\n            clippy::unnecessary_cast,\n            clippy::cast_lossless,\n            reason = \"cast is real when QuantityRaw is u64, no-op when u128\"\n        )]\n        scaled_raw_to_decimal(rescaled_raw as i128, self.precision)\n    }\n\n    /// Returns a raw fixed-point quantity as a `Decimal`.\n    #[must_use]\n    #[allow(\n        clippy::unnecessary_fallible_conversions,\n        reason = \"try_from is infallible when QuantityRaw is u64, fallible when u128\"\n    )]\n    pub(crate) fn raw_as_decimal(raw: QuantityRaw) -> Decimal {\n        let whole =\n            i128::try_from(raw / FIXED_SCALAR_RAW).expect(\"Whole raw quantity must fit in Decimal\");\n        let fractional = i128::try_from(raw % FIXED_SCALAR_RAW)\n            .expect(\"Fractional raw quantity must fit in Decimal\");\n\n        Decimal::from(whole) + Decimal::from_i128_with_scale(fractional, u32::from(FIXED_PRECISION))\n    }\n\n    /// Returns a formatted string representation of this instance.\n    #[must_use]\n    pub fn to_formatted_string(&self) -> String {\n        format!(\"{self}\").separate_with_underscores()\n    }\n\n    /// Creates a new [`Quantity`] from a `Decimal` value with specified precision.\n    ///\n    /// Uses pure integer arithmetic on the Decimal's mantissa and scale for fast conversion.\n    /// The value is rounded to the specified precision using banker's rounding (round half to even).\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if:","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/types/quantity.rs#L427-L463","documentation":"The fractional component of raw_as_decimal (raw % FIXED_SCALAR_RAW) is narrowed to i128 via try_from with expect. Because the remainder is strictly less than FIXED_SCALAR_RAW (10^FIXED_PRECISION, a small constant), this panic is only reachable if FIXED_SCALAR_RAW itself exceeded i128 range, i.e. an extreme fixed-precision configuration; it is a defensive invariant check rather than a condition callers can normally cause.","triggerScenarios":"Practically unreachable: raw_as_decimal would only panic here if the build's FIXED_PRECISION made FIXED_SCALAR_RAW larger than i128::MAX, since raw % FIXED_SCALAR_RAW is always < FIXED_SCALAR_RAW.","commonSituations":"Only conceivable in custom high-precision builds with pathological FIXED_PRECISION values; users of default builds will never encounter it.","solutions":["Nothing actionable for callers; if triggered, it indicates a broken build configuration of FIXED_PRECISION.","Keep FIXED_PRECISION at supported values (e.g. 9/16/18) so FIXED_SCALAR_RAW stays far below i128 range.","Report to maintainers if this panic is observed — it signals an internal invariant violation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["No caller-side defense is possible; this is an internal invariant check on FIXED_PRECISION configuration.","Use supported fixed-precision build values only.","Treat an occurrence as a library bug and report it."],"tags":["rust","panic","quantity","decimal","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}