* Bug 15599 fixed: now degree of zero polynomial is -Inf
[scilab.git] / scilab / modules / ast / includes / operations / types_opposite.hxx
1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
4 *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13 *
14 */
15
16 #ifndef __TYPES_OPPOSITE_HXX__
17 #define __TYPES_OPPOSITE_HXX__
18
19 #include "internal.hxx"
20 #include "sparse.hxx"
21 #include "polynom.hxx"
22 #include "bool.hxx"
23 #include "double.hxx"
24
25 void fillOppositeFunction();
26
27 //define arrays on operation functions
28 typedef types::InternalType*(*opposite_function)(types::InternalType*);
29
30 #define DECLARE_OPPOSITE_PROTO(x) template<class T, class O> types::InternalType* x(T *_pL)
31 DECLARE_OPPOSITE_PROTO(opposite_E);
32 DECLARE_OPPOSITE_PROTO(opposite_I);
33 DECLARE_OPPOSITE_PROTO(opposite_IC);
34 DECLARE_OPPOSITE_PROTO(opposite_S);
35 DECLARE_OPPOSITE_PROTO(opposite_SC);
36 DECLARE_OPPOSITE_PROTO(opposite_M);
37 DECLARE_OPPOSITE_PROTO(opposite_MC);
38
39 #undef DECLARE_OPPOSITE_PROTO
40
41 //do not inline it
42 template<> types::InternalType* opposite_M<types::Bool, types::Double>(types::Bool* _pL);
43
44 template<> types::InternalType* opposite_M<types::Sparse, types::Sparse>(types::Sparse* _pL);
45 template<> types::InternalType* opposite_MC<types::Sparse, types::Sparse>(types::Sparse* _pL);
46
47 template<> types::InternalType* opposite_S<types::Polynom, types::Polynom>(types::Polynom* _pL);
48 template<> types::InternalType* opposite_SC<types::Polynom, types::Polynom>(types::Polynom* _pL);
49 template<> types::InternalType* opposite_M<types::Polynom, types::Polynom>(types::Polynom* _pL);
50 template<> types::InternalType* opposite_MC<types::Polynom, types::Polynom>(types::Polynom* _pL);
51
52
53 template<typename T, typename O> inline static void opposite(T l, O* o)
54 {
55     *o = (O)(-l);
56 }
57
58 template<typename T, typename O> inline static void opposite(T l, T lc, O* o, O* oc)
59 {
60     *o = (O)(-l);
61     *oc = (O)(-lc);
62 }
63
64 template<typename T, typename O> inline static void opposite(T* l, long long size, O* o)
65 {
66     for (int i = 0; i < size ; ++i)
67     {
68         o[i] = (O)(-l[i]);
69     }
70 }
71
72 template<typename T, typename O> inline static void opposite(T* l, T* lc, long long size, O* o, O* oc)
73 {
74     for (int i = 0; i < size ; ++i)
75     {
76         o[i] = (O)(-l[i]);
77         oc[i] = (O)(-lc[i]);
78     }
79 }
80
81
82 #endif /* __TYPES_OPPOSITE_HXX__ */