You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "ftelnov (via GitHub)" <gi...@apache.org> on 2023/06/23 11:36:21 UTC

[GitHub] [avro] ftelnov commented on a diff in pull request #2299: AVRO-3781: [Rust] Enhance Decimal resolve

ftelnov commented on code in PR #2299:
URL: https://github.com/apache/avro/pull/2299#discussion_r1239712902


##########
lang/rust/avro/src/decimal.rs:
##########
@@ -53,6 +52,40 @@ impl Decimal {
         decimal_bytes[start_byte_index..].copy_from_slice(&raw_bytes);
         Ok(decimal_bytes)
     }
+
+    fn from_bigint(bigint: BigInt) -> Self {
+        let len = (bigint.bits() as f64 / 8.0).ceil() as usize;
+        Self { value: bigint, len }
+    }
+
+    // NOTE: conversion implementations below might be not that performant.
+    // It might be best to rewrite them using bits extraction and float number unpacking.
+
+    /// Converts from f32 by converting number to string firstly, then parsing it.
+    pub(crate) fn try_from_f32(num: f32) -> Result<Self, DecimalParsingError> {
+        if !num.is_finite() {}
+        let string = num.to_string();
+        string.parse()
+    }
+
+    /// Converts from f64 by converting number to string firstly, then parsing it.
+    pub(crate) fn try_from_f64(num: f64) -> Result<Self, DecimalParsingError> {
+        let string = num.to_string();
+        string.parse()
+    }
+
+    /// Returns digits amount of the `self`.
+    pub(crate) fn digits(&self) -> u64 {
+        // Since `num_bigint` crate has such an absurd amount of the encapsulation,

Review Comment:
   Yea, sorry, just got a little frustrated with such a limitation ;c
   fixed!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org