martin-g commented on code in PR #2299:
URL: https://github.com/apache/avro/pull/2299#discussion_r1235078836


##########
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() {}

Review Comment:
   What is the idea here ?



##########
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:
   Language please!
   There is no need to express your personal opinion all over the place! It 
does not help anyhow!



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to