Help! Strange Segmentation Fault Error for Recursive Matrix Fast Exponentiation

Revision en2, by duckladydinh, 2017-09-25 06:23:38

Hi friends,

During the implementation of matrix fast exponentiation, I have encountered a segmentation fault in the recursive approach. Even if I have managed to fix it by changing it to a loop, but I really want to know what is wrong with my code. I wonder if you can help me.

This is my recursive implementation. I cannot understand what is wrong with it.

Matrix fast_pow(Matrix &A, int n) {
if (n == 0) return ident(A.m);
if (n == 1) return A;
Matrix E = fast_pow(A, (n/2));
if (n % 2 == 1) {
return mul(E, A);
}
return E;
}



Thank you.

#### History

Revisions

Rev. Lang. By When Δ Comment