use crate::{
error::{EvalResult, InterpreterError},
value::Value,
};
pub(crate) fn dispatch_int_method(i: i64, method: &str, _args: &[Value]) -> EvalResult {
match method {
"bit_length" => {
let n = i.unsigned_abs();
let bits = if n == 0 { 0 } else { i64::from(u64::BITS - n.leading_zeros()) };
Ok(Value::Int(bits))
}
"bit_count" => {
let n = i.unsigned_abs();
Ok(Value::Int(i64::from(n.count_ones())))
}
"conjugate" | "real" => Ok(Value::Int(i)),
"imag" => Ok(Value::Int(0)),
_ => Err(InterpreterError::AttributeError(format!(
"'int' object has no attribute '{method}'"
))
.into()),
}
}