alamb commented on code in PR #9453:
URL: https://github.com/apache/arrow-rs/pull/9453#discussion_r3343230008
##########
arrow-buffer/src/bigint/mod.rs:
##########
@@ -614,6 +614,101 @@ impl i256 {
let n = (n.high >> 64) as i64; // throw away the lower 192 bits
(n as f64) * f64::powi(2.0, 192 - (k as i32)) // convert to f64 and
scale it, as we left-shift k bit previous, so we need to scale it by 2^(192-k)
}
+
+ /// Computes the `base` logarithm of the number `self`
+ /// Returns `None` if `self` is less than or equal to zero, or if `base`
is less than 2.
+ #[inline]
+ pub fn checked_ilog(self, base: i256) -> Option<u32> {
+ if base == Self::from(10) {
+ // Faster implementation for base 10
+ return self.checked_ilog10();
+ }
+
+ if self <= Self::ZERO {
+ return None;
+ }
+ if base <= Self::ONE {
+ return None;
+ }
+ if self <= base {
Review Comment:
Update: yes I think it should -- here is a PR that fixes it on your forl:
- https://github.com/theirix/arrow-rs/pull/1
##########
arrow-buffer/src/bigint/mod.rs:
##########
@@ -614,6 +614,101 @@ impl i256 {
let n = (n.high >> 64) as i64; // throw away the lower 192 bits
(n as f64) * f64::powi(2.0, 192 - (k as i32)) // convert to f64 and
scale it, as we left-shift k bit previous, so we need to scale it by 2^(192-k)
}
+
+ /// Computes the `base` logarithm of the number `self`
+ /// Returns `None` if `self` is less than or equal to zero, or if `base`
is less than 2.
+ #[inline]
+ pub fn checked_ilog(self, base: i256) -> Option<u32> {
+ if base == Self::from(10) {
+ // Faster implementation for base 10
+ return self.checked_ilog10();
+ }
+
+ if self <= Self::ZERO {
+ return None;
+ }
+ if base <= Self::ONE {
+ return None;
+ }
+ if self <= base {
Review Comment:
Shouldn't ilog(n, n) be 1 (not zero)?
--
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]