comparison liboctave/dNDArray.cc @ 4511:24af46b4ce84

[project @ 2003-09-12 16:46:04 by jwe]
author jwe
date Fri, 12 Sep 2003 16:46:04 +0000
parents
children 508238e65af7
comparison
equal deleted inserted replaced
4510:59eaa51e43d3 4511:24af46b4ce84
1 //N-D Array manipulations.
2 /*
3
4 Copyright (C) 1996, 1997 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 */
23
24 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
25 #pragma implementation
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32 #include "NDArray.h"
33 #include "mx-base.h"
34 #include "lo-ieee.h"
35
36 bool
37 NDArray::any_element_is_negative (bool neg_zero) const
38 {
39 int n = length ();
40 if (neg_zero)
41 {
42 for (int i = 0; i < n; i++)
43 if (lo_ieee_signbit (Array<double>::elem (i)))
44 return true;
45 }
46 else
47 {
48 for (int i = 0; i < n; i++)
49 if (Array<double>::elem (i) < 0)
50 return true;
51 }
52
53 return false;
54 }
55
56 bool
57 NDArray::all_integers (double& max_val, double& min_val) const
58 {
59 int n = length ();
60
61 if (n > 0)
62 {
63 max_val = Array<double>::elem (0);
64 min_val = Array<double>::elem (0);
65 }
66 else
67 return false;
68
69 for (int i = 0; i < n; i++)
70 {
71 double val = Array<double>::elem (0);
72
73 if (val > max_val)
74 max_val = val;
75
76 if (val < min_val)
77 min_val = val;
78
79 if (D_NINT (val) != val)
80 return false;
81 }
82
83 return true;
84 }