Mike.B
New Member
Hello everyone !
I have a trouble with my program and I don't know why.
Can you help me ?
I have MPLAB 8.92 + CSS and I have a PICKIT3.
So I would like to sum two matrices (and later, program a matrix multiplication).
My first code is about Integer matrices. It works very well.
I get : result[2][2]={{16,30},{20,22}}, that's correct.
Now, I would like to do the same think but not with Integer but with Double.
So, I change the "int" by "double" : it doesn't work.
Here is the code :
I get : result[2][2]={{16.0,0.0},{0.0,0.0}};
I don't understand why. Where is the problem ?
If someone could help, It would be wonderful.
Thanks and have a nice day !
I have a trouble with my program and I don't know why.
Can you help me ?
I have MPLAB 8.92 + CSS and I have a PICKIT3.
So I would like to sum two matrices (and later, program a matrix multiplication).
My first code is about Integer matrices. It works very well.
Code:
#include <18F45K20.h>
void sum(int **mat1,int **mat2, int **res){
int i=0;
int j=0;
int k=0;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
*(res+(1*i)+j)=*(mat1+(1*i)+j)+*(mat2+(1*i)+j);
}
}
}
int m1[2][2]={{15,30},{20,21}};
int m2[2][2]={{1,0},{0,1}};
int result[2][2];
void main()
{
sum(m1,m2,result);
while(1);
}
I get : result[2][2]={{16,30},{20,22}}, that's correct.
Now, I would like to do the same think but not with Integer but with Double.
So, I change the "int" by "double" : it doesn't work.
Here is the code :
Code:
#include <18F45K20.h>
void sum(double **mat1,double **mat2, double **res){
int i=0;
int j=0;
int k=0;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
*(res+(1*i)+j)=*(mat1+(1*i)+j)+*(mat2+(1*i)+j);
}
}
}
double m1[2][2]={{15.0,30.0},{20.0,21.0}};
double m2[2][2]={{1.0,0.0},{0.0,1.0}};
double result[2][2];
void main()
{
sum(m1,m2,result);
while(1);
}
I get : result[2][2]={{16.0,0.0},{0.0,0.0}};
I don't understand why. Where is the problem ?
If someone could help, It would be wonderful.
Thanks and have a nice day !