1
|
1 // tc-inlines.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 // Just a coupla more helper functions. |
|
25 |
|
26 static inline int |
|
27 tree_to_mat_idx (double x) |
|
28 { |
|
29 if (x > 0) |
|
30 return ((int) (x + 0.5) - 1); |
|
31 else |
|
32 return ((int) (x - 0.5) - 1); |
|
33 } |
|
34 |
|
35 static inline int |
|
36 range_max_check (int i, int imax) |
|
37 { |
|
38 i++; |
|
39 if (i > imax) |
|
40 { |
|
41 error ("matrix index = %d exceeds maximum dimension = %d", i, imax); |
|
42 jump_to_top_level (); |
|
43 } |
|
44 } |
|
45 |
|
46 static inline int |
|
47 range_max_check (int i, int j, int nr, int nc) |
|
48 { |
|
49 i++; |
|
50 if (i > nr) |
|
51 { |
|
52 error ("matrix row index = %d exceeds maximum row dimension = %d", |
|
53 i, nr); |
|
54 jump_to_top_level (); |
|
55 } |
|
56 |
|
57 j++; |
|
58 if (j > nc) |
|
59 { |
|
60 error ("matrix column index = %d exceeds maximum column dimension = %d", |
|
61 j, nc); |
|
62 jump_to_top_level (); |
|
63 } |
|
64 } |
|
65 |
|
66 static inline int |
|
67 indexed_assign_conforms (int lhs_nr, int lhs_nc, int rhs_nr, int rhs_nc) |
|
68 { |
|
69 return (lhs_nr == rhs_nr && lhs_nc == rhs_nc); |
|
70 } |
|
71 |
|
72 static inline int |
|
73 is_zero_one (const Range& r) |
|
74 { |
|
75 double b = r.base (); |
|
76 double l = r.limit (); |
|
77 return (NINT (b) == 0 && NINT (l) == 1 && r.nelem () == 2); |
|
78 } |
|
79 |
|
80 static inline void |
|
81 index_check (int i, char *rc) |
|
82 { |
|
83 if (i < 0) |
|
84 { |
|
85 error ("invalid %s index = %d", rc, i+1); |
|
86 jump_to_top_level (); |
|
87 } |
|
88 } |
|
89 |
|
90 static inline void |
|
91 index_check (const Range& r, int& max_val, char *rc) |
|
92 { |
|
93 double b = r.base (); |
|
94 int ib = tree_to_mat_idx (b); |
|
95 |
|
96 if (r.nelem () < 1) |
|
97 { |
|
98 error ("range invalid as %s index", rc); |
|
99 jump_to_top_level (); |
|
100 } |
|
101 |
|
102 if (ib < 0) |
|
103 { |
|
104 error ("invalid %s index = %d", rc, ib+1); |
|
105 jump_to_top_level (); |
|
106 } |
|
107 |
|
108 double lim = r.limit (); |
|
109 max_val = tree_to_mat_idx (lim); |
|
110 } |
|
111 |
|
112 static inline void |
|
113 index_check (const Range& r, char *rc) |
|
114 { |
|
115 int max_val; |
|
116 index_check (r, max_val, rc); |
|
117 } |
|
118 |
|
119 static inline int |
|
120 fortran_row (int i, int nr) |
|
121 { |
|
122 int r; |
|
123 r = i % nr; |
|
124 if (r == 0) |
|
125 r = nr; |
|
126 return r; |
|
127 } |
|
128 |
|
129 static inline int |
|
130 fortran_column (int i, int nr) |
|
131 { |
|
132 int c; |
|
133 int r; |
|
134 r = fortran_row (i, nr); |
|
135 c = (i - r) / nr + 1; |
|
136 return c; |
|
137 } |
|
138 |
|
139 static inline int |
|
140 valid_scalar_indices (tree_constant *args, int nargs) |
|
141 { |
|
142 int valid = args != NULL_TREE_CONST |
|
143 && ((nargs == 3 && args[2].valid_as_scalar_index () |
|
144 && args[1].valid_as_scalar_index ()) |
|
145 || (nargs == 2 && args[1].valid_as_scalar_index ())); |
|
146 |
|
147 return valid; |
|
148 } |
|
149 |
|
150 /* |
|
151 ;;; Local Variables: *** |
|
152 ;;; mode: C++ *** |
|
153 ;;; page-delimiter: "^/\\*" *** |
|
154 ;;; End: *** |
|
155 */ |