From 06da3df2ff648931ce65ed91bf516062828b2354 Mon Sep 17 00:00:00 2001 From: jofret Date: Fri, 1 Dec 2006 15:37:45 +0000 Subject: Quite a good DouComplex lib... Will probably be improved later... --- src/type/Makefile | 46 +++++++++++++++++++++++++++++++++----------- src/type/doubleComplex.c | 22 ++++++++++++++++++++- src/type/doubleComplex.h | 6 +++++- src/type/main.c | 23 ---------------------- src/type/testDoubleComplex.c | 23 ++++++++++++++++++++++ 5 files changed, 84 insertions(+), 36 deletions(-) delete mode 100644 src/type/main.c create mode 100644 src/type/testDoubleComplex.c diff --git a/src/type/Makefile b/src/type/Makefile index 8b34532e..4894baa8 100644 --- a/src/type/Makefile +++ b/src/type/Makefile @@ -5,28 +5,52 @@ ## Made by Bruno JOFRET ## ## Started on Thu Nov 30 16:33:40 2006 jofret -## Last update Thu Nov 30 17:52:34 2006 jofret +## Last update Fri Dec 1 16:21:12 2006 jofret ## ## Copyright INRIA 2006 ## -NAME = dummy +NAME = complex RM = rm -f CC = gcc -CFLAGS = -Wall -pedantic +CFLAGS = -Wall -pedantic -ansi +AR = ar cru +RANLIB = ranlib -SRC = doubleComplex.c \ - main.c +OBJS = $(DCOBJ) $(FCOBJ) +LIBS = $(DCLIB) $(FCLIB) -HEADERS = doubleComplex.h +### test -OBJ = $(SRC:.c=.o) -all: $(SRC) $(HEADERS) $(OBJ) - $(CC) $(CFLAGS) $(OBJ) -o $(NAME) +### Double Complex +DCLIB = libDoubleComplex.a +DCSRC = doubleComplex.c +DCHEAD = doubleComplex.h +DCOBJ = $(DCSRC:.c=.o) + +### Float Complex +FCLIB = libFloatComplex.a +FCSRC = floatComplex.c +FCHEAD = floatComplex.h +FCOBJ = $(FCSRC:.c=.o) + + +all: $(LIBS) + +$(DCLIB) : $(DCOBJ) + $(AR) $@ $< + $(RANLIB) $@ + +$(FCLIB) : $(FCOBJ) + $(AR) $@ $< + $(RANLIB) $@ clean: - $(RM) $(OBJ) + $(RM) $(OBJS) distclean: clean - $(RM) $(NAME) \ No newline at end of file + $(RM) $(NAME) $(LIBS) + +test: $(NAME) + diff --git a/src/type/doubleComplex.c b/src/type/doubleComplex.c index b05ca0d0..071553b8 100644 --- a/src/type/doubleComplex.c +++ b/src/type/doubleComplex.c @@ -5,7 +5,7 @@ ** Made by Bruno JOFRET ** ** Started on Thu Nov 30 16:27:08 2006 jofret -** Last update Thu Nov 30 17:59:50 2006 jofret +** Last update Fri Dec 1 15:17:20 2006 jofret ** ** Copyright INRIA 2006 */ @@ -39,3 +39,23 @@ doubleComplex DoubleComplex(double real, double imag) { z.imag = imag; return z; } + +/* +** \function isreal +** \brief check if complex is real . +*/ +bool isreal(doubleComplex z) { + if (z.imag == 0) + return true; + return false; +} + +/* +** \function isimag +** \brief check if complex is pure imaginary . +*/ +bool isimag(doubleComplex z) { + if (z.real == 0) + return true; + return false; +} diff --git a/src/type/doubleComplex.h b/src/type/doubleComplex.h index 7d96b72f..c1943e0e 100644 --- a/src/type/doubleComplex.h +++ b/src/type/doubleComplex.h @@ -5,7 +5,7 @@ ** Made by Bruno JOFRET ** ** Started on Thu Nov 30 16:50:08 2006 jofret -** Last update Thu Nov 30 17:53:13 2006 jofret +** Last update Fri Dec 1 15:17:05 2006 jofret ** ** Copyright INRIA 2006 */ @@ -13,6 +13,8 @@ #ifndef __DOUBLECOMPLEX_H__ #define __DOUBLECOMPLEX_H__ +#include + struct double_complex { double real; @@ -24,5 +26,7 @@ typedef struct double_complex doubleComplex; double real(doubleComplex); double imag(doubleComplex); doubleComplex DoubleComplex(double, double); +bool isreal(doubleComplex); +bool isimag(doubleComplex); #endif /* !__DOUBLECOMPLEX_H__ */ diff --git a/src/type/main.c b/src/type/main.c deleted file mode 100644 index 0372c93a..00000000 --- a/src/type/main.c +++ /dev/null @@ -1,23 +0,0 @@ -/* -** -*- C -*- -** -** main.c -** Made by Bruno JOFRET -** -** Started on Thu Nov 30 16:59:04 2006 jofret -** Last update Thu Nov 30 17:55:50 2006 jofret -** -** Copyright INRIA 2006 -*/ - -#include - -#include "doubleComplex.h" - -int main(int argc, char **argv) { - /* z = 1 + %i */ - doubleComplex z = DoubleComplex(-3,25); - printf("Partie reelle = %f\n", real(z)); - printf("Partie imaginaire = %f\n", imag(z)); - return 0; -} diff --git a/src/type/testDoubleComplex.c b/src/type/testDoubleComplex.c new file mode 100644 index 00000000..0372c93a --- /dev/null +++ b/src/type/testDoubleComplex.c @@ -0,0 +1,23 @@ +/* +** -*- C -*- +** +** main.c +** Made by Bruno JOFRET +** +** Started on Thu Nov 30 16:59:04 2006 jofret +** Last update Thu Nov 30 17:55:50 2006 jofret +** +** Copyright INRIA 2006 +*/ + +#include + +#include "doubleComplex.h" + +int main(int argc, char **argv) { + /* z = 1 + %i */ + doubleComplex z = DoubleComplex(-3,25); + printf("Partie reelle = %f\n", real(z)); + printf("Partie imaginaire = %f\n", imag(z)); + return 0; +} -- cgit