Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / dirac.cpp
blob410b3a8dedcf252381b92077aeaab300f78b85a2
1 //-----------------------------------------------------------------------------
2 //
3 // Author : philippe.billet@noos.fr
4 //
5 // Dirac function dirac(x)
6 // dirac(-x)=dirac(x)
7 // dirac(b-a)=dirac(a-b)
8 //-----------------------------------------------------------------------------
10 #include "stdafx.h"
11 #include "defs.h"
12 static void ydirac(void);
14 void
15 eval_dirac(void)
17 push(cadr(p1));
18 eval();
19 dirac();
22 void
23 dirac(void)
25 save();
26 ydirac();
27 restore();
30 #define X p1
32 static void
33 ydirac(void)
36 X = pop();
40 if (isdouble(X)) {
41 if (X->u.d == 0)
42 {push_integer(1);
43 return;}
44 else
45 {push_integer(0);
46 return;}
49 if (isrational(X)) {
50 if (MZERO(mmul(X->u.q.a,X->u.q.b)))
51 {push_integer(1);
52 return;}
53 else
54 {push_integer(0);
55 return;}
59 if (car(X) == symbol(POWER)) {
60 push_symbol(DIRAC);
61 push(cadr(X));
62 list(2);
63 return;
66 if (isnegativeterm(X)) {
67 push_symbol(DIRAC);
68 push(X);
69 negate();
70 list(2);
71 return;
74 if (isnegativeterm(p1) || (car(p1) == symbol(ADD) && isnegativeterm(cadr(p1)))) {
75 push(p1);
76 negate();
77 p1 = pop();
81 push_symbol(DIRAC);
82 push(X);
83 list(2);
86 #if SELFTEST
88 static char *s[] = {
91 "dirac(-x)",
92 "dirac(x)",
95 void
96 test_dirac(void)
98 test(__FILE__, s, sizeof s / sizeof (char *));
101 #endif