EMAN2
byteorder.cpp
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#include "byteorder.h"
33#include "util.h"
34
35using namespace EMAN;
36
37bool ByteOrder::is_host_endian_checked = false;
38bool ByteOrder::host_big_endian = false;
39
40bool ByteOrder::is_host_big_endian()
41{
43 int one = 1;
44 char *p_one = (char *) (&one);
45
46 if (p_one[0] == 1 && p_one[1] == 0 && p_one[2] == 0 && p_one[3] == 0) {
47 host_big_endian = false;
48 }
49 else {
50 host_big_endian = true;
51 }
52
54 }
55
56 return host_big_endian;
57}
58
60{
61 bool is_big = false;
62
63 if (Util::goodf(&f) && f > 0 && f < 65535.0 && f == floor(f)) {
64 is_big = is_host_big_endian();
65 }
66 else {
67 is_big = !is_host_big_endian();
68 }
69
70 return is_big;
71}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
static bool is_host_endian_checked
Definition: byteorder.h:149
static bool host_big_endian
Definition: byteorder.h:150
static bool is_float_big_endian(float small_number)
given a small floating number, return whether the number is in big endian or not.
Definition: byteorder.cpp:59
static int goodf(const float *p_f)
Check whether a number is a good float.
Definition: util.h:1112
E2Exception class.
Definition: aligner.h:40