annotate examples/make_int.cc @ 14200:64d9f33313cc stable rc-3-6-0-1

3.6.0-rc1 release candidate * configure.ac (AC_INIT): Version is now 3.6.0-rc1. (OCTAVE_RELEASE_DATE): Now 2012-01-12.
author John W. Eaton <jwe@octave.org>
date Thu, 12 Jan 2012 14:31:50 -0500
parents b099acf06b55
children 224e76250443
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
1 #include <octave/config.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
2
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
3 #include <cstdlib>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
4
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
5 #include <string>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
6
4320
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
7 #include <ostream>
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
8
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
9 #include <octave/lo-mappers.h>
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
10 #include <octave/lo-utils.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
11 #include <octave/mx-base.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
12 #include <octave/str-vec.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
13
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
14 #include <octave/defun-dld.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
15 #include <octave/error.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
16 #include <octave/gripes.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
17 #include <octave/oct-obj.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
18 #include <octave/ops.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
19 #include <octave/ov-base.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
20 #include <octave/ov-typeinfo.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
21 #include <octave/ov.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
22 #include <octave/ov-scalar.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
23 #include <octave/pager.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
24 #include <octave/pr-output.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
25 #include <octave/symtab.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
26 #include <octave/variables.h>
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
27
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
28 class octave_value_list;
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
29
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
30 class tree_walker;
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
31
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
32 // Integer values.
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
33
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
34 class
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
35 octave_integer : public octave_base_value
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
36 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
37 public:
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
38
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
39 octave_integer (void)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
40 : octave_base_value (), scalar (0) { }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
41
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
42 octave_integer (int i)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
43 : octave_base_value (), scalar (i) { }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
44
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
45 octave_integer (const octave_integer& s)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
46 : octave_base_value (), scalar (s.scalar) { }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
47
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
48 ~octave_integer (void) { }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
49
6445
407c08a8e5b7 [project @ 2007-03-23 19:20:12 by jwe]
jwe
parents: 5307
diff changeset
50 octave_base_value *clone (void) { return new octave_integer (*this); }
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
51
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
52 #if 0
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
53 void *operator new (size_t size);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
54 void operator delete (void *p, size_t size);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
55 #endif
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
56
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
57 idx_vector index_vector (void) const { return idx_vector ((double) scalar); }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
58
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
59 int rows (void) const { return 1; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
60 int columns (void) const { return 1; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
61
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3328
diff changeset
62 bool is_constant (void) const { return true; }
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3328
diff changeset
63
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
64 bool is_defined (void) const { return true; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
65 bool is_real_scalar (void) const { return true; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
66
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
67 octave_value all (void) const { return (double) (scalar != 0); }
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
68 octave_value any (void) const { return (double) (scalar != 0); }
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
69
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
70 bool is_real_type (void) const { return true; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
71 bool is_scalar_type (void) const { return true; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
72 bool is_numeric_type (void) const { return true; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
73
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
74 bool valid_as_scalar_index (void) const
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
75 { return scalar == 1; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
76
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
77 bool valid_as_zero_index (void) const
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
78 { return scalar == 0; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
79
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
80 bool is_true (void) const { return (scalar != 0); }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
81
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
82 double double_value (bool = false) const { return (double) scalar; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
83
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
84 int integer_value (bool = false) const { return scalar; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
85
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
86 Matrix matrix_value (bool = false) const { return Matrix (1, 1, scalar); }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
87
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
88 Complex complex_value (bool = false) const { return scalar; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
89
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
90 ComplexMatrix complex_matrix_value (bool = false) const
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
91 { return ComplexMatrix (1, 1, Complex (scalar)); }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
92
4320
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
93 octave_value gnot (void) const { return octave_value ((double) ! scalar); }
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
94
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
95 octave_value uminus (void) const { return new octave_integer (- scalar); }
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
96
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
97 octave_value transpose (void) const { return new octave_integer (scalar); }
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
98
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
99 octave_value hermitian (void) const { return new octave_integer (scalar); }
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
100
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
101 void increment (void) { ++scalar; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
102
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
103 void decrement (void) { --scalar; }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
104
4320
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
105 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
106
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
107 private:
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
108
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
109 int scalar;
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
110
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
111 DECLARE_OCTAVE_ALLOCATOR
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
112
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
113 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
114 };
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
115
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
116 void
4320
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
117 octave_integer::print (std::ostream& os, bool pr_as_read_syntax) const
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
118 {
4320
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
119 os << scalar;
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
120 // octave_print_internal (os, scalar, pr_as_read_syntax);
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
121 }
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
122
3327
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
123 #ifdef DEFUNOP_OP
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
124 #undef DEFUNOP_OP
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
125 #endif
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
126
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
127 #define DEFUNOP_OP(name, t, op) \
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
128 UNOPDECL (name, a) \
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
129 { \
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
130 CAST_UNOP_ARG (const octave_ ## t&); \
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
131 return octave_value (new octave_integer (op v.t ## _value ())); \
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
132 }
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
133
4320
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
134 DEFUNOP_OP (gnot, integer, !)
3327
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
135 DEFUNOP_OP (uminus, integer, -)
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
136 DEFUNOP_OP (transpose, integer, /* no-op */)
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
137 DEFUNOP_OP (hermitian, integer, /* no-op */)
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
138
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
139 DEFNCUNOP_METHOD (incr, integer, increment)
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
140 DEFNCUNOP_METHOD (decr, integer, decrement)
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
141
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
142 #ifdef DEFBINOP_OP
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
143 #undef DEFBINOP_OP
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
144 #endif
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
145
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
146 #define DEFBINOP_OP(name, t1, t2, op) \
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
147 BINOPDECL (name, a1, a2) \
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
148 { \
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
149 CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
150 return octave_value \
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
151 (new octave_integer (v1.t1 ## _value () op v2.t2 ## _value ())); \
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
152 }
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
153
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
154 // integer by integer ops.
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
155
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
156 DEFBINOP_OP (add, integer, integer, +)
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
157 DEFBINOP_OP (sub, integer, integer, -)
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
158 DEFBINOP_OP (mul, integer, integer, *)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
159
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
160 DEFBINOP (div, integer, integer)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
161 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
162 CAST_BINOP_ARGS (const octave_integer&, const octave_integer&);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
163
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
164 int d = v2.integer_value ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
165
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
166 if (d == 0)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
167 gripe_divide_by_zero ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
168
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
169 return new octave_integer (v1.integer_value () / d);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
170 }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
171
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
172
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
173 DEFBINOP (i_s_div, integer, scalar)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
174 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
175 CAST_BINOP_ARGS (const octave_integer&, const octave_scalar&);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
176
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
177 double d = v2.double_value ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
178
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
179 if (d == 0.0)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
180 gripe_divide_by_zero ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
181
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
182 return new octave_scalar (v1.double_value () / d);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
183 }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
184
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
185 DEFBINOP (ldiv, integer, integer)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
186 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
187 CAST_BINOP_ARGS (const octave_integer&, const octave_integer&);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
188
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
189 int d = v1.integer_value ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
190
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
191 if (d == 0)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
192 gripe_divide_by_zero ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
193
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
194 return new octave_integer (v2.integer_value () / d);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
195 }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
196
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
197 DEFBINOP_OP (lt, integer, integer, <)
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
198 DEFBINOP_OP (le, integer, integer, <=)
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
199 DEFBINOP_OP (eq, integer, integer, ==)
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
200 DEFBINOP_OP (ge, integer, integer, >=)
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
201 DEFBINOP_OP (gt, integer, integer, >)
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
202 DEFBINOP_OP (ne, integer, integer, !=)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
203
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
204 DEFBINOP_OP (el_mul, integer, integer, !=)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
205
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
206 DEFBINOP (el_div, integer, integer)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
207 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
208 CAST_BINOP_ARGS (const octave_integer&, const octave_integer&);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
209
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
210 int d = v2.integer_value ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
211
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
212 if (d == 0)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
213 gripe_divide_by_zero ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
214
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
215 return new octave_integer (v1.integer_value () / d);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
216 }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
217
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
218 DEFBINOP (el_ldiv, integer, integer)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
219 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
220 CAST_BINOP_ARGS (const octave_integer&, const octave_integer&);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
221
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
222 int d = v1.integer_value ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
223
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
224 if (d == 0)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
225 gripe_divide_by_zero ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
226
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
227 return new octave_integer (v2.integer_value () / d);
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
228 }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
229
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
230 DEFBINOP_OP (el_and, integer, integer, &&)
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
231 DEFBINOP_OP (el_or, integer, integer, ||)
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
232
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
233 DEFUN_DLD (make_int, args, ,
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
234 "int_val = make_int (val)\n\
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
235 \n\
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
236 Creates an integer variable from VAL.")
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
237 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
238 static bool type_loaded = false;
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
239
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
240 if (! type_loaded)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
241 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
242 octave_integer::register_type ();
11052
b099acf06b55 make_int.cc: don't pass arg to mlock
John W. Eaton <jwe@octave.org>
parents: 11051
diff changeset
243 mlock ();
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
244
4320
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
245 octave_stdout << "installing integer type at type-id = "
9932
6cb30a539481 untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents: 9053
diff changeset
246 << octave_integer::static_type_id () << "\n";
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
247
4320
cc3a9c2608bd [project @ 2003-02-13 21:09:31 by jwe]
jwe
parents: 3603
diff changeset
248 INSTALL_UNOP (op_not, octave_integer, gnot);
3603
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
249 INSTALL_UNOP (op_uminus, octave_integer, uminus);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
250 INSTALL_UNOP (op_transpose, octave_integer, transpose);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
251 INSTALL_UNOP (op_hermitian, octave_integer, hermitian);
3327
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
252
3603
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
253 INSTALL_NCUNOP (op_incr, octave_integer, incr);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
254 INSTALL_NCUNOP (op_decr, octave_integer, decr);
3327
bb81f9dcdac7 [project @ 1999-10-30 03:56:27 by jwe]
jwe
parents: 3304
diff changeset
255
3603
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
256 INSTALL_BINOP (op_add, octave_integer, octave_integer, add);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
257 INSTALL_BINOP (op_sub, octave_integer, octave_integer, sub);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
258 INSTALL_BINOP (op_mul, octave_integer, octave_integer, mul);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
259 INSTALL_BINOP (op_div, octave_integer, octave_integer, div);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
260 INSTALL_BINOP (op_ldiv, octave_integer, octave_integer, ldiv);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
261 INSTALL_BINOP (op_lt, octave_integer, octave_integer, lt);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
262 INSTALL_BINOP (op_le, octave_integer, octave_integer, le);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
263 INSTALL_BINOP (op_eq, octave_integer, octave_integer, eq);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
264 INSTALL_BINOP (op_ge, octave_integer, octave_integer, ge);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
265 INSTALL_BINOP (op_gt, octave_integer, octave_integer, gt);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
266 INSTALL_BINOP (op_ne, octave_integer, octave_integer, ne);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
267 INSTALL_BINOP (op_el_mul, octave_integer, octave_integer, el_mul);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
268 INSTALL_BINOP (op_el_div, octave_integer, octave_integer, el_div);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
269 INSTALL_BINOP (op_el_ldiv, octave_integer, octave_integer, el_ldiv);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
270 INSTALL_BINOP (op_el_and, octave_integer, octave_integer, el_and);
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
271 INSTALL_BINOP (op_el_or, octave_integer, octave_integer, el_or);
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
272
3603
de4471c26cd3 [project @ 2000-02-29 07:59:54 by jwe]
jwe
parents: 3354
diff changeset
273 INSTALL_BINOP (op_div, octave_integer, octave_scalar, i_s_div);
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
274 }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
275
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
276 octave_value retval;
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
277
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
278 if (args.length () == 1)
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
279 {
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
280 double d = args(0).double_value ();
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
281
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
282 if (! error_state)
9932
6cb30a539481 untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents: 9053
diff changeset
283 retval = octave_value (new octave_integer (NINT (d)));
2391
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
284 }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
285 else
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
286 usage ("make_int");
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
287
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
288 return retval;
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
289 }
b12625d6fbcd [project @ 1996-10-12 19:35:37 by jwe]
jwe
parents:
diff changeset
290
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
291 DEFUN_DLD (doit, args, ,
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
292 "doit (I)")
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
293 {
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
294 octave_value_list retval;
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
295
3328
c447b7fa53e8 [project @ 1999-10-30 04:02:56 by jwe]
jwe
parents: 3327
diff changeset
296 if (args(0).type_id () == octave_integer::static_type_id ())
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
297 {
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
298 // At this point, we know we have a handle for an octave_integer
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
299 // object, so we can peek at the representation and extract the
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
300 // data.
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
301
6445
407c08a8e5b7 [project @ 2007-03-23 19:20:12 by jwe]
jwe
parents: 5307
diff changeset
302 const octave_base_value& rep = args(0).get_rep ();
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
303
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
304 int my_value = ((const octave_integer&) rep) . integer_value ();
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
305
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
306 message ("doit", "your lucky number is: %d", my_value);
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
307 }
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
308 else
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
309 gripe_wrong_type_arg ("doit", args(0));
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
310
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
311 return retval;
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
312 }
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
313
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
314 DEFINE_OCTAVE_ALLOCATOR (octave_integer);
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
315
5172
9d9bbda4f00c [project @ 2005-03-01 18:26:20 by jwe]
jwe
parents: 4320
diff changeset
316 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_integer, "integer", "integer");