# HG changeset patch # User John W. Eaton # Date 1378761191 14400 # Node ID 0b644adf4f310ebaaa74a2ccbaba08dc6f4e8da5 # Parent ed149e891876fa150b36951a1fc80bde4568e7a3 speak CHAR_BIT in C++-ese * bitfcns.cc, typecast.cc, data-conv.cc: Instead of CHAR_BIT, use std::numeric_limits::digits. diff -r ed149e891876 -r 0b644adf4f31 libinterp/corefcn/bitfcns.cc --- a/libinterp/corefcn/bitfcns.cc Mon Sep 09 08:47:06 2013 -0700 +++ b/libinterp/corefcn/bitfcns.cc Mon Sep 09 17:13:11 2013 -0400 @@ -24,6 +24,8 @@ #include #endif +#include + #include "str-vec.h" #include "quit.h" @@ -588,7 +590,7 @@ mask = mask >> (bits_in_mantissa - nbits); else if (nbits < 1) mask = 0; - int bits_in_type = sizeof (double) * CHAR_BIT; + int bits_in_type = sizeof (double) * std::numeric_limits::digits; NDArray m = m_arg.array_value (); DO_BITSHIFT ( ); } @@ -601,7 +603,7 @@ mask = mask >> (bits_in_mantissa - nbits); else if (nbits < 1) mask = 0; - int bits_in_type = sizeof (float) * CHAR_BIT; + int bits_in_type = sizeof (float) * std::numeric_limits::digits; FloatNDArray m = m_arg.float_array_value (); DO_BITSHIFT (Float); } diff -r ed149e891876 -r 0b644adf4f31 libinterp/corefcn/typecast.cc --- a/libinterp/corefcn/typecast.cc Mon Sep 09 08:47:06 2013 -0700 +++ b/libinterp/corefcn/typecast.cc Mon Sep 09 17:13:11 2013 -0400 @@ -25,7 +25,7 @@ #include #endif -#include +#include #include "mx-base.h" @@ -242,9 +242,9 @@ do_bitpack (const boolNDArray& bitp) { typedef typename ArrayType::element_type T; - octave_idx_type n = bitp.numel () / (sizeof (T) * CHAR_BIT); + octave_idx_type n = bitp.numel () / (sizeof (T) * std::numeric_limits::digits); - if (n * static_cast (sizeof (T)) * CHAR_BIT == bitp.numel ()) + if (n * static_cast (sizeof (T)) * std::numeric_limits::digits == bitp.numel ()) { ArrayType retval (get_vec_dims (bitp.dims (), n)); @@ -257,11 +257,11 @@ for (octave_idx_type i = 0; i < m; i++) { char c = bits[0]; - for (int j = 1; j < CHAR_BIT; j++) + for (int j = 1; j < std::numeric_limits::digits; j++) c |= bits[j] << j; packed[i] = c; - bits += CHAR_BIT; + bits += std::numeric_limits::digits; } return retval; @@ -361,22 +361,22 @@ do_bitunpack (const ArrayType& array) { typedef typename ArrayType::element_type T; - octave_idx_type n = array.numel () * sizeof (T) * CHAR_BIT; + octave_idx_type n = array.numel () * sizeof (T) * std::numeric_limits::digits; boolNDArray retval (get_vec_dims (array.dims (), n)); const char *packed = reinterpret_cast (array.fortran_vec ()); bool *bits = retval.fortran_vec (); - octave_idx_type m = n / CHAR_BIT; + octave_idx_type m = n / std::numeric_limits::digits; for (octave_idx_type i = 0; i < m; i++) { char c = packed[i]; bits[0] = c & 1; - for (int j = 1; j < CHAR_BIT; j++) + for (int j = 1; j < std::numeric_limits::digits; j++) bits[j] = (c >>= 1) & 1; - bits += CHAR_BIT; + bits += std::numeric_limits::digits; } return retval; diff -r ed149e891876 -r 0b644adf4f31 liboctave/util/data-conv.cc --- a/liboctave/util/data-conv.cc Mon Sep 09 08:47:06 2013 -0700 +++ b/liboctave/util/data-conv.cc Mon Sep 09 17:13:11 2013 -0400 @@ -25,10 +25,10 @@ #endif #include -#include #include #include +#include #include #include "byte-swap.h" @@ -45,7 +45,7 @@ #define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \ do \ { \ - int sz = BITS / CHAR_BIT; \ + int sz = BITS / std::numeric_limits::digits; \ if (sizeof (TQ char) == sz) \ VAL = oct_data_conv::dt_ ## Q ## char; \ else if (sizeof (TQ short) == sz) \ @@ -64,7 +64,7 @@ #define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \ do \ { \ - int sz = BITS / CHAR_BIT; \ + int sz = BITS / std::numeric_limits::digits; \ if (sizeof (TQ char) == sz) \ VAL = oct_data_conv::dt_ ## Q ## char; \ else if (sizeof (TQ short) == sz) \ @@ -82,7 +82,7 @@ #define FIND_SIZED_FLOAT_TYPE(VAL, BITS) \ do \ { \ - int sz = BITS / CHAR_BIT; \ + int sz = BITS / std::numeric_limits::digits; \ if (sizeof (float) == sz) \ VAL = oct_data_conv::dt_float; \ else if (sizeof (double) == sz) \ @@ -94,8 +94,9 @@ // I'm not sure it is worth the trouble, but let's use a lookup table // for the types that are supposed to be a specific number of bits -// wide. Given the macros above, this should work as long as CHAR_BIT -// is a multiple of 8 and there are types with the right sizes. +// wide. Given the macros above, this should work as long as +// std::numeric_limits::digits is a multiple of 8 and +// there are types with the right sizes. // // The sized data type lookup table has the following format: //