Hey. I have a program that raises a number to a power. But if, for example, in my function the type of all the numbers i8 and my result is more or less than the number 127 and -128, I get to get panic (this is in IDE), but in the usual console I get some random numbers, even negative ones that number with a plus sign.
This test helps, but very crookedly:
if result > 127 || result < -128 || number >= 0 && result < 0 {
println!("Some error text..");
} else {
println!("Result: {}", result);
}
How to solve this problem?
P.S. This is my simple pow function:
fn pow(n: i8, p: i8) -> i8 {
if p == 1 {
return n;
}
n * pow(n, p - 1)
}
Is it possible for me to handle this function using a match? I tried, but it did not work