Mercurial > hg > octave-nkf
comparison liboctave/Range.cc @ 1360:7eb93d12654c
[project @ 1995-09-05 21:51:54 by jwe]
author | jwe |
---|---|
date | Tue, 05 Sep 1995 21:51:54 +0000 |
parents | 611d403c7f3d |
children | 9f9131a8d706 |
comparison
equal
deleted
inserted
replaced
1359:a6994c934a50 | 1360:7eb93d12654c |
---|---|
133 } | 133 } |
134 | 134 |
135 return is; | 135 return is; |
136 } | 136 } |
137 | 137 |
138 int | |
139 Range::nelem_internal (void) const | |
140 { | |
141 // Find an approximate number of intervals, then do the best we can to | 138 // Find an approximate number of intervals, then do the best we can to |
142 // find the number of intervals that we would get if we had done | 139 // find the number of intervals that we would get if we had done |
143 // something like | 140 // something like |
144 // | 141 // |
145 // nelem = 0; | 142 // nelem = 0; |
149 // (for limit > base && inc > 0) | 146 // (for limit > base && inc > 0) |
150 // | 147 // |
151 // The number of elements in the range is one greater than the number | 148 // The number of elements in the range is one greater than the number |
152 // of intervals. | 149 // of intervals. |
153 | 150 |
154 // We can't have more than INT_MAX elements in the range. | 151 int |
152 Range::nelem_internal (void) const | |
153 { | |
154 // We can't have more than INT_MAX elements in the range. | |
155 | 155 |
156 double d_n_intervals = (rng_limit - rng_base) / rng_inc; | 156 double d_n_intervals = (rng_limit - rng_base) / rng_inc; |
157 int max_intervals = INT_MAX - 1; | 157 int max_intervals = INT_MAX - 1; |
158 double d_max_val = (double) max_intervals; | 158 double d_max_val = (double) max_intervals; |
159 | 159 |
164 ? ((int) (d_n_intervals + 0.5)) | 164 ? ((int) (d_n_intervals + 0.5)) |
165 : ((int) (d_n_intervals - 0.5)); | 165 : ((int) (d_n_intervals - 0.5)); |
166 | 166 |
167 if (rng_limit > rng_base && rng_inc > 0) | 167 if (rng_limit > rng_base && rng_inc > 0) |
168 { | 168 { |
169 // Our approximation may have been too big. | 169 // Our approximation may have been too big. |
170 | 170 |
171 while (rng_base + n_intervals * rng_inc > rng_limit && n_intervals > 0) | 171 while (rng_base + n_intervals * rng_inc > rng_limit && n_intervals > 0) |
172 n_intervals--; | 172 n_intervals--; |
173 | 173 |
174 // Now that we are close, get the actual number. Try to avoid | 174 // Now that we are close, get the actual number. Try to avoid |
175 // problems with extended precision registers. | 175 // problems with extended precision registers. |
176 | 176 |
177 for (;;) | 177 for (;;) |
178 { | 178 { |
179 volatile double tmp_inc = (n_intervals + 1) * rng_inc; | 179 volatile double tmp_inc = (n_intervals + 1) * rng_inc; |
180 volatile double tmp_val = rng_base + tmp_inc; | 180 volatile double tmp_val = rng_base + tmp_inc; |
184 break; | 184 break; |
185 } | 185 } |
186 } | 186 } |
187 else if (rng_limit < rng_base && rng_inc < 0) | 187 else if (rng_limit < rng_base && rng_inc < 0) |
188 { | 188 { |
189 // Our approximation may have been too big. | 189 // Our approximation may have been too big. |
190 | 190 |
191 while (rng_base + n_intervals * rng_inc < rng_limit && n_intervals > 0) | 191 while (rng_base + n_intervals * rng_inc < rng_limit && n_intervals > 0) |
192 n_intervals--; | 192 n_intervals--; |
193 | 193 |
194 // Now that we are close, get the actual number. Try to avoid | 194 // Now that we are close, get the actual number. Try to avoid |
195 // problems with extended precision registers. | 195 // problems with extended precision registers. |
196 | 196 |
197 for (;;) | 197 for (;;) |
198 { | 198 { |
199 volatile double tmp_inc = (n_intervals + 1) * rng_inc; | 199 volatile double tmp_inc = (n_intervals + 1) * rng_inc; |
200 volatile double tmp_val = rng_base + tmp_inc; | 200 volatile double tmp_val = rng_base + tmp_inc; |