octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

double(true) not implemented


From: John W. Eaton
Subject: double(true) not implemented
Date: Wed, 15 Sep 2004 21:10:12 -0400

On 15-Sep-2004, Josep Monés i Teixidor <address@hidden> wrote:

| Perhaps this is being worked on but in case nobody noticed explicit
| conversion from logical to double fails (although implicit conversion
| works as a workaround by now):
| 
| octave:1> double(true)
| error: invalid conversion from bool to scalar
| octave:1> true+0
| ans = 1

Please try the following patch.

This will also make things like

  int32 (true)

work.

Thanks,

jwe


src/ChangeLog:

2004-09-15  John W. Eaton  <address@hidden>

        * OPERATORS/op-int-conv.cc: Define and install bool to int
        conversions.
        * OPERATORS/op-double-conv.cc: Define and install bool to double
        conversions.

 
Index: src/OPERATORS/op-double-conv.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/OPERATORS/op-double-conv.cc,v
retrieving revision 1.1
diff -u -r1.1 op-double-conv.cc
--- a/src/OPERATORS/op-double-conv.cc   14 Jun 2004 18:33:02 -0000      1.1
+++ b/src/OPERATORS/op-double-conv.cc   16 Sep 2004 01:05:26 -0000
@@ -39,6 +39,8 @@
 #include "ov-uint16.h"
 #include "ov-uint32.h"
 #include "ov-uint64.h"
+#include "ov-bool.h"
+#include "ov-bool-mat.h"
 #include "ov-scalar.h"
 #include "ov-re-mat.h"
 #include "ov-typeinfo.h"
@@ -66,6 +68,9 @@
 DEFDBLCONVFN (uint32_scalar_to_double_matrix, uint32_scalar, uint32_array)
 DEFDBLCONVFN (uint64_scalar_to_double_matrix, uint64_scalar, uint64_array)
 
+DEFDBLCONVFN (bool_matrix_to_double_matrix, bool_matrix, bool_array)
+DEFDBLCONVFN (bool_scalar_to_double_matrix, bool, bool_array)
+
 DEFDBLCONVFN (double_scalar_to_double_matrix, scalar, array)
 
 void
@@ -91,6 +96,9 @@
   INSTALL_CONVOP (octave_uint32_scalar, octave_matrix, 
uint32_scalar_to_double_matrix);
   INSTALL_CONVOP (octave_uint64_scalar, octave_matrix, 
uint64_scalar_to_double_matrix);
 
+  INSTALL_CONVOP (octave_bool_matrix, octave_matrix, 
bool_matrix_to_double_matrix);
+  INSTALL_CONVOP (octave_bool, octave_matrix, bool_scalar_to_double_matrix);
+
   INSTALL_CONVOP (octave_scalar, octave_matrix, 
double_scalar_to_double_matrix);
 }
 
@@ -98,4 +106,4 @@
 ;;; Local Variables: ***
 ;;; mode: C++ ***
 ;;; End: ***
-*/
+p*/
Index: src/OPERATORS/op-int-conv.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/OPERATORS/op-int-conv.cc,v
retrieving revision 1.3
diff -u -r1.3 op-int-conv.cc
--- a/src/OPERATORS/op-int-conv.cc      1 Sep 2004 00:49:06 -0000       1.3
+++ b/src/OPERATORS/op-int-conv.cc      16 Sep 2004 01:05:26 -0000
@@ -40,6 +40,8 @@
 #include "ov-uint32.h"
 #include "ov-uint64.h"
 #include "ov-range.h"
+#include "ov-bool.h"
+#include "ov-bool-mat.h"
 #include "ov-scalar.h"
 #include "ov-re-mat.h"
 #include "ov-typeinfo.h"
@@ -67,6 +69,26 @@
 DEFCONVFN (matrix_to_uint32, matrix, uint32)
 DEFCONVFN (matrix_to_uint64, matrix, uint64)
 
+DEFCONVFN (bool_to_int8, bool, int8)
+DEFCONVFN (bool_to_int16, bool, int16)
+DEFCONVFN (bool_to_int32, bool, int32)
+DEFCONVFN (bool_to_int64, bool, int64)
+
+DEFCONVFN (bool_to_uint8, bool, uint8)
+DEFCONVFN (bool_to_uint16, bool, uint16)
+DEFCONVFN (bool_to_uint32, bool, uint32)
+DEFCONVFN (bool_to_uint64, bool, uint64)
+
+DEFCONVFN (bool_matrix_to_int8, bool_matrix, int8)
+DEFCONVFN (bool_matrix_to_int16, bool_matrix, int16)
+DEFCONVFN (bool_matrix_to_int32, bool_matrix, int32)
+DEFCONVFN (bool_matrix_to_int64, bool_matrix, int64)
+
+DEFCONVFN (bool_matrix_to_uint8, bool_matrix, uint8)
+DEFCONVFN (bool_matrix_to_uint16, bool_matrix, uint16)
+DEFCONVFN (bool_matrix_to_uint32, bool_matrix, uint32)
+DEFCONVFN (bool_matrix_to_uint64, bool_matrix, uint64)
+
 DEFCONVFN (range_to_int8, range, int8)
 DEFCONVFN (range_to_int16, range, int16)
 DEFCONVFN (range_to_int32, range, int32)
@@ -145,6 +167,8 @@
 {
   INSTALL_CONVOPS (scalar)
   INSTALL_CONVOPS (matrix)
+  INSTALL_CONVOPS (bool)
+  INSTALL_CONVOPS (bool_matrix)
   INSTALL_CONVOPS (range)
 
   INSTALL_INT_CONV_FUNCTIONS (int8)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]