1 /*
2     This file is part of GNU APL, a free implementation of the
3     ISO/IEC Standard 13751, "Programming Language APL, Extended"
4 
5     Copyright (C) 2008-2015  Dr. Jürgen Sauermann
6 
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef __NUMERICCELL_HH_DEFINED__
22 #define __NUMERICCELL_HH_DEFINED__
23 
24 #include "Cell.hh"
25 
26 //-----------------------------------------------------------------------------
27 /*! A cell that is either an integer cell, a floating point cell, or a
28     complex number cell. This class contains all cell functions for which
29     the detailed type makes no difference.
30 */
31 /// Base class for RealCell and ComplexCell
32 class NumericCell : public Cell
33 {
34 protected:
35    /// overloaded Cell::is_numeric()
is_numeric() const36    virtual bool is_numeric() const
37       { return true; }
38 
39    /// overloaded Cell::bif_not()
40    virtual ErrorCode bif_not(Cell * Z) const;
41 
42    /// overloaded Cell::bif_not_bitwise()
43    virtual ErrorCode bif_not_bitwise(Cell * Z) const;
44 
45    /// overloaded Cell::bif_and()
46    virtual ErrorCode bif_and(Cell * Z, const Cell * A) const;
47 
48    /// overloaded Cell::bif_and_bitwise()
49    virtual ErrorCode bif_and_bitwise(Cell * Z, const Cell * A) const;
50 
51    /// overloaded Cell::bif_equal_bitwise()
52    virtual ErrorCode bif_equal_bitwise(Cell * Z, const Cell * A) const;
53 
54    /// overloaded Cell::bif_not_equal_bitwise()
55    virtual ErrorCode bif_not_equal_bitwise(Cell * Z, const Cell * A) const;
56 
57    /// overloaded Cell::bif_binomial()
58    virtual ErrorCode bif_binomial(Cell * Z, const Cell * A) const;
59 
60    /// compute binomial funtion for integers a and b
61    static void do_binomial(Cell * Z, APL_Integer a, APL_Integer b, bool negate);
62 
63    /// overloaded Cell::bif_nand()
64    virtual ErrorCode bif_nand(Cell * Z, const Cell * A) const;
65 
66    /// overloaded Cell::bif_nand_bitwise()
67    virtual ErrorCode bif_nand_bitwise(Cell * Z, const Cell * A) const;
68 
69    /// overloaded Cell::bif_nor()
70    virtual ErrorCode bif_nor(Cell * Z, const Cell * A) const;
71 
72    /// overloaded Cell::bif_nor_bitwise()
73    virtual ErrorCode bif_nor_bitwise(Cell * Z, const Cell * A) const;
74 
75    /// overloaded Cell::bif_or()
76    virtual ErrorCode bif_or(Cell * Z, const Cell * A) const;
77 
78    /// overloaded Cell::bif_or_bitwise()
79    virtual ErrorCode bif_or_bitwise(Cell * Z, const Cell * A) const;
80 
81    /// overloaded Cell::get_classname()
get_classname() const82    virtual const char * get_classname() const   { return "NumericCell"; }
83 
84    /// return the greatest common divisor of integers a and b
85    static ErrorCode int_gcd(APL_Integer & z, APL_Integer a, APL_Integer b);
86 
87    /// return the greatest common divisor of real a and b
88    static ErrorCode flt_gcd(APL_Float & z, APL_Float a, APL_Float b,
89                             double qct);
90 
91    /// return the greatest common divisor of complex a and b
92    static ErrorCode cpx_gcd(APL_Complex & z, APL_Complex a, APL_Complex b,
93                               double qct);
94 
95    /// multiply \b a by 1, -1, i, or -i so that a.real is maximal
96    static APL_Complex cpx_max_real(APL_Complex a);
97 };
98 //-----------------------------------------------------------------------------
99 
100 #endif // __NUMERICCELL_HH_DEFINED__
101