[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Testing endianness
From: |
John W. Eaton |
Subject: |
Testing endianness |
Date: |
Fri, 16 Jan 2004 09:49:06 -0800 |
On 16-Jan-2004, Jean-Francois Cardoso <address@hidden> wrote:
| I am porting some code from matlab to octave which needs to determine
| the endianness of the machine, as shown below in the original matlab
| version. Some adjustments are needed because octave's computer() does
| not return the same strings. I could make these changes on an ad hoc
| basis, adding new tests each time I want to run the code on a
| different machine. BUT, maybe someone knows of a clean way to test
| for endianness. Is there a simpler/more robust way to find out?
|
| Could jwe think of adding a function (like isieee() for instance)
| which would return the endianness of the machine? I did not see
| anything related. That would be better than letting the user parse
| strings.
|
| Thanks, JFC
|
| % First try to figure out if we need to swap bytes.
| %
| friend = computer;
| if strmatch(friend,'PCWIN') bswap = 'b';
| elseif strmatch(friend,'LNX86') bswap = 'b';
| elseif strmatch(friend,'GLNX86') bswap = 'b';
| elseif strmatch(friend,'ALPHA') bswap = 'b';
| else bswap = 'l';
| end
How about the following patch? With it
octave_config_info ("words_big_endian")
and
octave_config_info ("words_little_endian")
return TRUE or FALSE, and
octave_config_info ("float_format")
will return a string (either ieee_big_endian or ieee_little_endian on
most current systems where Octave can actually run, the notable
exception being the Cray SV1).
jwe
src/ChangeLog:
2004-01-16 John W. Eaton <address@hidden>
* toplev.cc (octave_config_info): Add float_format,
words_big_endian, and words_little_endian to the struct.
Index: src/toplev.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/toplev.cc,v
retrieving revision 1.148
diff -u -r1.148 toplev.cc
--- src/toplev.cc 10 Jan 2004 18:16:03 -0000 1.148
+++ src/toplev.cc 16 Jan 2004 17:45:24 -0000
@@ -743,6 +743,16 @@
{
m.assign ("dld", octave_value (octave_supports_dynamic_linking));
+ oct_mach_info::float_format ff = oct_mach_info::native_float_format ();
+ m.assign ("float_format",
+ octave_value (oct_mach_info::float_format_as_string (ff)));
+
+ m.assign ("words_big_endian",
+ octave_value (oct_mach_info::words_big_endian ()));
+
+ m.assign ("words_little_endian",
+ octave_value (oct_mach_info::words_little_endian ()));
+
int i = 0;
while (true)
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Testing endianness, Jean-Francois Cardoso, 2004/01/16
- Testing endianness,
John W. Eaton <=