summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjofret2007-02-06 10:59:29 +0000
committerjofret2007-02-06 10:59:29 +0000
commit4eebffd88476ff84eaae4b55f79d13e63893e416 (patch)
treec698e52d3ab7387a53f7ccb80b6359df4f074aa8 /src
parent938d363f979742c697b190b36568ac35b84decab (diff)
downloadscilab2c-4eebffd88476ff84eaae4b55f79d13e63893e416.tar.gz
scilab2c-4eebffd88476ff84eaae4b55f79d13e63893e416.tar.bz2
scilab2c-4eebffd88476ff84eaae4b55f79d13e63893e416.zip
* src/type :
Add C99 compatibility. Float implementation. * src/elementaryFunctions/cos/zcoss.c Fixed with C99 Complex but Scilab computation. * src/elementaryFunctions/cos/ccoss.c Fixed with C99 Complex but Scilab computation.
Diffstat (limited to 'src')
-rw-r--r--src/elementaryFunctions/cos/ccoss.c14
-rw-r--r--src/elementaryFunctions/cos/zcoss.c14
-rw-r--r--src/type/floatComplex.c31
-rw-r--r--src/type/floatComplex.h22
-rw-r--r--src/type/floatComplexC99.h32
5 files changed, 83 insertions, 30 deletions
diff --git a/src/elementaryFunctions/cos/ccoss.c b/src/elementaryFunctions/cos/ccoss.c
index 79c18fb4..91a822fa 100644
--- a/src/elementaryFunctions/cos/ccoss.c
+++ b/src/elementaryFunctions/cos/ccoss.c
@@ -5,14 +5,22 @@
** Made by Bruno JOFRET <bruno.jofret@inria.fr>
**
** Started on Thu Dec 7 12:04:28 2006 jofret
-** Last update Wed Jan 31 10:19:53 2007 jofret
+** Last update Mon Feb 5 17:24:00 2007 jofret
**
** Copyright INRIA 2006
*/
#include "floatComplex.h"
+float scoss(float);
+float scoshs(float);
+float ssins(float);
+float ssinhs(float);
+
floatComplex ccoss(floatComplex z) {
- /* FIXME: Dummy... */
- return z;
+ float real = creal(z);
+ float imag = cimag(z);
+
+ return FloatComplex(scoss(real) * scoshs(imag),
+ -ssins(real) * ssinhs(imag));
}
diff --git a/src/elementaryFunctions/cos/zcoss.c b/src/elementaryFunctions/cos/zcoss.c
index f12391de..c5fe96bc 100644
--- a/src/elementaryFunctions/cos/zcoss.c
+++ b/src/elementaryFunctions/cos/zcoss.c
@@ -5,14 +5,22 @@
** Made by Bruno JOFRET <bruno.jofret@inria.fr>
**
** Started on Thu Dec 7 12:05:48 2006 jofret
-** Last update Wed Jan 31 10:19:12 2007 jofret
+** Last update Mon Feb 5 17:25:27 2007 jofret
**
** Copyright INRIA 2006
*/
#include "doubleComplex.h"
+double dcoss(double);
+double dcoshs(double);
+double dsins(double);
+double dsinhs(double);
+
doubleComplex zcoss(doubleComplex z) {
- /* FIXME: Dummy... */
- return (DoubleComplex(0,1));
+ double real = creal(z);
+ double imag = cimag(z);
+
+ return DoubleComplex(dcoss(real) * dcoshs(imag),
+ -dsins(real) * dsinhs(imag));
}
diff --git a/src/type/floatComplex.c b/src/type/floatComplex.c
index eecc3a8e..f696e594 100644
--- a/src/type/floatComplex.c
+++ b/src/type/floatComplex.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 Thu Dec 7 11:44:05 2006 jofret
+** Last update Mon Feb 5 17:19:08 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 "floatComplex.h"
+#else
+#include "floatComplexC99.h"
+#endif
+#ifndef STDC99
/*
** \function real
** \brief Return a Complex Real Part .
*/
-float real(floatComplex z) {
+float creal(floatComplex z) {
return z.real;
}
@@ -24,9 +40,10 @@ float real(floatComplex z) {
** \function imag
** \brief Return a Complex Imaginary Part .
*/
-float imag(floatComplex z) {
+float cimag(floatComplex z) {
return z.imag;
}
+#endif
/*
** \function FloatComplex
@@ -34,8 +51,12 @@ float imag(floatComplex z) {
*/
floatComplex FloatComplex(float real, float imag) {
floatComplex z;
+#ifndef STDC99
z.real = real;
z.imag = imag;
+#else
+ z = real + I * imag;
+#endif
return z;
}
@@ -44,7 +65,7 @@ floatComplex FloatComplex(float real, float imag) {
** \brief check if complex is real .
*/
bool isreal(floatComplex z) {
- if (z.imag == 0)
+ if (creal(z) == 0)
return true;
return false;
}
@@ -54,7 +75,7 @@ bool isreal(floatComplex z) {
** \brief check if complex is pure imaginary .
*/
bool isimag(floatComplex z) {
- if (z.real == 0)
+ if (cimag(z) == 0)
return true;
return false;
}
diff --git a/src/type/floatComplex.h b/src/type/floatComplex.h
index abfcb602..10e26408 100644
--- a/src/type/floatComplex.h
+++ b/src/type/floatComplex.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:20 2007 jofret
+** Last update Mon Feb 5 17:11:51 2007 jofret
**
** Copyright INRIA 2006
*/
@@ -13,7 +13,6 @@
#ifndef __FLOATCOMPLEX_H__
#define __FLOATCOMPLEX_H__
-#ifndef STDC99
/*
** Hand made Float Complex definition
** {
@@ -28,8 +27,8 @@ struct float_complex
typedef struct float_complex floatComplex;
-float real(floatComplex);
-float imag(floatComplex);
+float creal(floatComplex);
+float cimag(floatComplex);
floatComplex FloatComplex(float, float);
bool isreal(floatComplex);
bool isimag(floatComplex);
@@ -37,19 +36,4 @@ bool isimag(floatComplex);
** }
*/
-#else
-
-/*
-** Use standard C99 Double Complex definition
-** {
-*/
-#include <complex.h>
-
-typedef double complex doubleComplex;
-/*
-** }
-*/
-
-#endif /* !STDC99 */
-
#endif /* !__FLOATCOMPLEX_H__ */
diff --git a/src/type/floatComplexC99.h b/src/type/floatComplexC99.h
new file mode 100644
index 00000000..ef37abf8
--- /dev/null
+++ b/src/type/floatComplexC99.h
@@ -0,0 +1,32 @@
+/*
+** -*- C -*-
+**
+** floatComplexC99.h
+** Made by Bruno JOFRET <bruno.jofret@inria.fr>
+**
+** Started on Mon Feb 5 17:09:35 2007 jofret
+** Last update Mon Feb 5 17:10:50 2007 jofret
+**
+** Copyright INRIA 2007
+*/
+
+#ifndef __FLOATCOMPLEXC99_H__
+#define __FLOATCOMPLEXC99_H__
+
+/*
+** Use standard C99 float Complex definition
+** {
+*/
+#include <stdbool.h>
+#include <complex.h>
+
+typedef float complex floatComplex;
+
+floatComplex FloatComplex(float, float);
+bool isreal(floatComplex);
+bool isimag(floatComplex);
+/*
+** }
+*/
+
+#endif /* !__DOUBLE_COMPLEX_C99__ */