00001 /* 00002 00003 Copyright (C) 2003-2012 John W. Eaton 00004 00005 This file is part of Octave. 00006 00007 Octave is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 3 of the License, or (at your 00010 option) any later version. 00011 00012 Octave is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Octave; see the file COPYING. If not, see 00019 <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #ifdef HAVE_CONFIG_H 00024 #include <config.h> 00025 #endif 00026 00027 #include "data-conv.h" 00028 00029 #include "ls-utils.h" 00030 00031 // MAX_VAL and MIN_VAL are assumed to have integral values even though 00032 // they are stored in doubles. 00033 00034 save_type 00035 get_save_type (double /* max_val */, double /* min_val */) 00036 { 00037 save_type st = LS_DOUBLE; 00038 00039 // Matlab doesn't seem to load the UINT32 type correctly, so let's 00040 // avoid it (and the other unsigned types, even though they may not 00041 // have the same problem. And apparently, there are problems with 00042 // other smaller types as well. If we avoid them all, then maybe we 00043 // will avoid problems. Unfortunately, we won't be able to save 00044 // space... 00045 00046 // if (max_val < 256 && min_val > -1) 00047 // st = LS_U_CHAR; 00048 // else if (max_val < 65536 && min_val > -1) 00049 // st = LS_U_SHORT; 00050 // else if (max_val < 4294967295UL && min_val > -1) 00051 // st = LS_U_INT; 00052 // else if (max_val < 128 && min_val >= -128) 00053 // st = LS_CHAR; 00054 // else if (max_val < 32768 && min_val >= -32768) 00055 // st = LS_SHORT; 00056 // else if (max_val <= 2147483647L && min_val >= -2147483647L) 00057 // st = LS_INT; 00058 00059 return st; 00060 } 00061 00062 save_type 00063 get_save_type (float /* max_val */, float /* min_val */) 00064 { 00065 save_type st = LS_FLOAT; 00066 00067 // Matlab doesn't seem to load the UINT32 type correctly, so let's 00068 // avoid it (and the other unsigned types, even though they may not 00069 // have the same problem. And apparently, there are problems with 00070 // other smaller types as well. If we avoid them all, then maybe we 00071 // will avoid problems. Unfortunately, we won't be able to save 00072 // space... 00073 00074 // if (max_val < 256 && min_val > -1) 00075 // st = LS_U_CHAR; 00076 // else if (max_val < 65536 && min_val > -1) 00077 // st = LS_U_SHORT; 00078 // else if (max_val < 4294967295UL && min_val > -1) 00079 // st = LS_U_INT; 00080 // else if (max_val < 128 && min_val >= -128) 00081 // st = LS_CHAR; 00082 // else if (max_val < 32768 && min_val >= -32768) 00083 // st = LS_SHORT; 00084 // else if (max_val <= 2147483647L && min_val >= -2147483647L) 00085 // st = LS_INT; 00086 00087 return st; 00088 }