diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/type/Makefile | 22 | ||||
-rw-r--r-- | src/type/doubleComplex.c | 33 | ||||
-rw-r--r-- | src/type/doubleComplex.h | 22 | ||||
-rw-r--r-- | src/type/doubleComplexC99.h | 33 | ||||
-rw-r--r-- | src/type/testDoubleComplex.c | 29 |
6 files changed, 108 insertions, 36 deletions
@@ -1,3 +1,8 @@ +2007-02-02 Bruno JOFRET <bruno.jofret@inria.fr> + + * src/type : + Add C99 compatibility. Double implementation. + 2007-01-31 Bruno JOFRET <bruno.jofret@inria.fr> * src/elementaryFunctions/*.c : diff --git a/src/type/Makefile b/src/type/Makefile index 77bb93c4..b7ed4846 100644 --- a/src/type/Makefile +++ b/src/type/Makefile @@ -5,22 +5,25 @@ ## Made by Bruno JOFRET <bruno.jofret@inria.fr> ## ## Started on Thu Nov 30 16:33:40 2006 jofret -## Last update Thu Dec 7 15:04:27 2006 jofret +## Last update Fri Feb 2 15:37:53 2007 jofret ## ## Copyright INRIA 2006 ## RM = rm -f CC = gcc -CFLAGS = -Wall -pedantic -ansi -Werror +CFLAGS = -Wall -pedantic -ansi $(STANDARD) AR = ar cru RANLIB = ranlib -OBJS = $(DCOBJ) $(FCOBJ) +OBJS = $(DCOBJ) $(FCOBJ) $(TESTDCOBJ) $(TESTFCOBJ) LIBS = $(DCLIB) $(FCLIB) +TESTS = $(TESTDC) $(TESTFC) ### test - +TESTDCSRC = testDoubleComplex.c +TESTDCOBJ = $(TESTDCSRC:.c=.o) +TESTDC = testDoubleComplex ### Double Complex DCLIB = ../lib/libDoubleComplex.a @@ -44,11 +47,20 @@ $(DCLIB) : $(DCHEAD) $(DCOBJ) $(FCLIB) : $(FCHEAD) $(FCOBJ) $(AR) $@ $(FCOBJ) $(RANLIB) $@ + +test: $(TESTDC) + + +$(TESTDC) : $(DCOBJ) $(TESTDCOBJ) + $(CC) $(CFLAGS) $(DCOBJ) $(TESTDCOBJ) -o $@ + clean: $(RM) $(OBJS) distclean: clean - $(RM) $(LIBS) + $(RM) $(LIBS) $(TESTS) re: clean all +retest: clean test + diff --git a/src/type/doubleComplex.c b/src/type/doubleComplex.c index 717d2c4d..648bf408 100644 --- a/src/type/doubleComplex.c +++ b/src/type/doubleComplex.c @@ -5,18 +5,34 @@ ** Made by Bruno JOFRET <bruno.jofret@inria.fr> ** ** Started on Thu Nov 30 16:27:08 2006 jofret -** Last update Wed Jan 31 16:11:51 2007 jofret +** Last update Fri Feb 2 15:40:47 2007 jofret ** ** Copyright INRIA 2006 */ +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif + +#ifndef STDC99 #include "doubleComplex.h" +#else +#include "doubleComplexC99.h" +#endif +#ifndef STDC99 /* -** \function real +** \function creal ** \brief Return a Complex Real Part . */ -double real(doubleComplex z) { +double creal(doubleComplex z) { return z.real; } @@ -24,9 +40,10 @@ double real(doubleComplex z) { ** \function imag ** \brief Return a Complex Imaginary Part . */ -double imag(doubleComplex z) { +double cimag(doubleComplex z) { return z.imag; } +#endif /* ** \function DoubleComplex @@ -34,8 +51,12 @@ double imag(doubleComplex z) { */ doubleComplex DoubleComplex(double real, double imag) { doubleComplex z; +#ifndef STDC99 z.real = real; z.imag = imag; +#else + z = real + I * imag; +#endif return z; } @@ -44,7 +65,7 @@ doubleComplex DoubleComplex(double real, double imag) { ** \brief check if complex is real . */ bool isreal(doubleComplex z) { - if (z.imag == 0) + if (cimag(z) == 0) return true; return false; } @@ -54,7 +75,7 @@ bool isreal(doubleComplex z) { ** \brief check if complex is pure imaginary . */ bool isimag(doubleComplex z) { - if (z.real == 0) + if (creal(z) == 0) return true; return false; } diff --git a/src/type/doubleComplex.h b/src/type/doubleComplex.h index 3f73f169..c29248a9 100644 --- a/src/type/doubleComplex.h +++ b/src/type/doubleComplex.h @@ -5,7 +5,7 @@ ** Made by Bruno JOFRET <bruno.jofret@inria.fr> ** ** Started on Thu Nov 30 16:50:08 2006 jofret -** Last update Wed Jan 31 10:14:18 2007 jofret +** Last update Fri Feb 2 15:40:27 2007 jofret ** ** Copyright INRIA 2006 */ @@ -13,7 +13,6 @@ #ifndef __DOUBLECOMPLEX_H__ #define __DOUBLECOMPLEX_H__ -#ifndef STDC99 /* ** Hand made Double Complex definition ** { @@ -28,8 +27,8 @@ struct double_complex typedef struct double_complex doubleComplex; -double real(doubleComplex); -double imag(doubleComplex); +double creal(doubleComplex); +double cimag(doubleComplex); doubleComplex DoubleComplex(double, double); bool isreal(doubleComplex); bool isimag(doubleComplex); @@ -37,19 +36,4 @@ bool isimag(doubleComplex); ** } */ -#else - -/* -** Use standard C99 Double Complex definition -** { -*/ -#include <complex.h> - -typedef double complex doubleComplex; -/* -** } -*/ - -#endif /* !STDC99 */ - #endif /* !__DOUBLECOMPLEX_H__ */ diff --git a/src/type/doubleComplexC99.h b/src/type/doubleComplexC99.h new file mode 100644 index 00000000..984d5e06 --- /dev/null +++ b/src/type/doubleComplexC99.h @@ -0,0 +1,33 @@ +/* +** -*- C -*- +** +** doubleComplexC99.h +** Made by Bruno JOFRET <bruno.jofret@inria.fr> +** +** Started on Thu Feb 1 17:01:39 2007 jofret +** Last update Fri Feb 2 10:49:40 2007 jofret +** +** Copyright INRIA 2007 +*/ + + +#ifndef __DOUBLECOMPLEXC99_H__ +#define __DOUBLECOMPLEXC99_H__ + +/* +** Use standard C99 Double Complex definition +** { +*/ +#include <stdbool.h> +#include <complex.h> + +typedef double complex doubleComplex; + +doubleComplex DoubleComplex(double, double); +bool isreal(doubleComplex); +bool isimag(doubleComplex); +/* +** } +*/ + +#endif /* !__DOUBLE_COMPLEX_C99__ */ diff --git a/src/type/testDoubleComplex.c b/src/type/testDoubleComplex.c index 0372c93a..5ca02f98 100644 --- a/src/type/testDoubleComplex.c +++ b/src/type/testDoubleComplex.c @@ -5,19 +5,36 @@ ** Made by Bruno JOFRET <bruno.jofret@inria.fr> ** ** Started on Thu Nov 30 16:59:04 2006 jofret -** Last update Thu Nov 30 17:55:50 2006 jofret +** Last update Fri Feb 2 15:39:31 2007 jofret ** ** Copyright INRIA 2006 */ -#include <stdio.h> +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif + +#ifndef STDC99 +# include <stdio.h> +# include "doubleComplex.h" +#else +# include <stdio.h> +# include <complex.h> +# include "doubleComplexC99.h" +#endif -#include "doubleComplex.h" int main(int argc, char **argv) { - /* z = 1 + %i */ + /* z = -3 + 25*%i */ doubleComplex z = DoubleComplex(-3,25); - printf("Partie reelle = %f\n", real(z)); - printf("Partie imaginaire = %f\n", imag(z)); + printf("Partie reelle = %f\n", creal(z)); + printf("Partie imaginaire = %f\n", cimag(z)); return 0; } |