diff options
author | torset | 2009-02-16 15:13:08 +0000 |
---|---|---|
committer | torset | 2009-02-16 15:13:08 +0000 |
commit | 26242eeede601928daefb94e9b62ce8d52252e94 (patch) | |
tree | e74909ea93feea08adc24273288b97ac7d2e10dd /src/matrixOperations/spec/testFloatSpec.c | |
parent | c65b1f4148b46436b9d61fe6d7c1aa048080a960 (diff) | |
download | scilab2c-26242eeede601928daefb94e9b62ce8d52252e94.tar.gz scilab2c-26242eeede601928daefb94e9b62ce8d52252e94.tar.bz2 scilab2c-26242eeede601928daefb94e9b62ce8d52252e94.zip |
Add spec, which computes the eigenvalues of the matrix
Diffstat (limited to 'src/matrixOperations/spec/testFloatSpec.c')
-rw-r--r-- | src/matrixOperations/spec/testFloatSpec.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/matrixOperations/spec/testFloatSpec.c b/src/matrixOperations/spec/testFloatSpec.c new file mode 100644 index 00000000..421746ff --- /dev/null +++ b/src/matrixOperations/spec/testFloatSpec.c @@ -0,0 +1,115 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2008 - INRIA - Arnaud TORSET + * + * This file must be used under the terms of the CeCILL. + * This source file is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at + * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + * + */ + + +#include "spec.h" +#include "stdio.h" +#include "assert.h" +#include "math.h" + +static void sspecaTest(void){ + float in[4]={1.0f,1.0f,1.0f,3.0f}; + float resultR[2]={0.5857864376269050765700f,3.4142135623730949234300f}; + float resultI[2]={0.0f,0.0f}; + + float in2[4]={1.0f,1.0f,-2.0f,3.0f}; + float result2R[2]={1.9999999999999997779554f,1.9999999999999997779554f}; + float result2I[2]={0.9999999999999997779554f,-0.9999999999999997779554f}; + + floatComplex *out; + + int i; + + out=malloc((uint)2*sizeof(floatComplex)); + + sspeca(in,2,out); + for (i=0;i<2;i++) printf("%f+%f*i\n",creals(out[i]) ,cimags(out[i])); + for(i=0;i<2;i++){ + if (creals(out[i])>1e-16) assert( fabs(creals(out[i])-resultR[i]) / fabs(creals(out[i])) <1e-16); + else assert(1); + if (cimags(out[i])>1e-16) assert( fabs(cimags(out[i])-resultI[i]) / fabs(cimags(out[i])) <1e-16); + else assert(1); + } + + + + sspeca(in2,2,out); + + for (i=0;i<2;i++) printf("%f+%f*i\n",creals(out[i]) ,cimags(out[i])); + + for(i=0;i<2;i++){ + if (creals(out[i])>1e-16) assert( fabs(creals(out[i])-result2R[i]) / fabs(creals(out[i])) <1e-16); + else assert(1); + if (cimags(out[i])>1e-16) assert( fabs(cimags(out[i])-result2I[i]) / fabs(cimags(out[i])) <1e-16); + else assert(1); + } +} + + + + +static void cspecaTest(void){ + float inR[4]={1.0f,1.0f,1.0f,3.0f}; + float inI[4]={0.0f,0.0f,0.0f,0.0f}; + float resultR[2]={0.5857864376269050765700f,3.4142135623730949234300f}; + float resultI[2]={0,0}; + + float in2R[4]={1.0f,1.0f,-2.0f,3.0f}; + float in2I[4]={0.0f,0.0f,0.0f,0.0f}; + float result2R[2]={1.9999999999999997779554f,1.9999999999999997779554f}; + float result2I[2]={0.9999999999999997779554f,-0.9999999999999997779554f}; + + floatComplex *in,*in2,out[4]; + + int i; + + in=FloatComplexMatrix(inR,inI,4); + in2=FloatComplexMatrix(in2R,in2I,4); + + cspeca(in,2,out); + for(i=0;i<2;i++){ + if (creals(out[i])>1e-16) assert( fabs(creals(out[i])-resultR[i]) / fabs(creals(out[i])) <1e-15); + else assert(1); + if (cimags(out[i])>1e-16) assert( fabs(cimags(out[i])-resultI[i]) / fabs(cimags(out[i])) <1e-16); + else assert(1); + } + + + cspeca(in2,2,out); + for(i=0;i<2;i++){ + if (creals(out[i])>1e-16) assert( fabs(creals(out[i])-result2R[i]) / fabs(creals(out[i])) <1e-15); + else assert(1); + if (cimags(out[i])>1e-16) assert( fabs(cimags(out[i])-result2I[i]) / fabs(cimags(out[i])) <1e-15); + else assert(1); + } + +} + + + + +static int testSpec(void){ + printf(">>> Float Spec Tests <<<\n"); + printf(">>> Float <<<\n"); + sspecaTest(); + printf(">>> FloatComplex <<<\n"); + cspecaTest(); + return 0; +} + + +int main(void){ + assert (testSpec()==0); + + + return 0; +} |