|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #ifndef QNUM_H |
|
44 #define QNUM_H |
|
45 |
|
46 // |
|
47 // W A R N I N G |
|
48 // ------------- |
|
49 // |
|
50 // This file is not part of the Qt API. It exists purely as an |
|
51 // implementation detail. This header file may change from version to |
|
52 // version without notice, or even be removed. |
|
53 // |
|
54 // We mean it. |
|
55 // |
|
56 |
|
57 #include "QtCore/qglobal.h" |
|
58 |
|
59 static const unsigned char qt_be_inf_bytes[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }; |
|
60 static const unsigned char qt_le_inf_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }; |
|
61 static inline double qtInf() |
|
62 { |
|
63 return *reinterpret_cast<const double *>(QSysInfo::ByteOrder == QSysInfo::BigEndian ? qt_be_inf_bytes : qt_le_inf_bytes); |
|
64 } |
|
65 #define Q_INFINITY (::qtInf()) |
|
66 |
|
67 // Signaling NAN |
|
68 static const unsigned char qt_be_snan_bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 }; |
|
69 static const unsigned char qt_le_snan_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f }; |
|
70 static inline double qtSnan() |
|
71 { |
|
72 return *reinterpret_cast<const double *>(QSysInfo::ByteOrder == QSysInfo::BigEndian ? qt_be_snan_bytes : qt_le_snan_bytes); |
|
73 } |
|
74 #define Q_SNAN (::qtSnan()) |
|
75 |
|
76 // Quiet NAN |
|
77 static const unsigned char qt_be_qnan_bytes[] = { 0xff, 0xf8, 0, 0, 0, 0, 0, 0 }; |
|
78 static const unsigned char qt_le_qnan_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0xff }; |
|
79 static inline double qtQnan() |
|
80 { |
|
81 return *reinterpret_cast<const double *>(QSysInfo::ByteOrder == QSysInfo::BigEndian ? qt_be_qnan_bytes : qt_le_qnan_bytes); |
|
82 } |
|
83 #define Q_QNAN (::qtQnan()) |
|
84 |
|
85 static inline bool qIsInf(double d) |
|
86 { |
|
87 uchar *ch = (uchar *)&d; |
|
88 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
89 return (ch[0] & 0x7f) == 0x7f && ch[1] == 0xf0; |
|
90 } else { |
|
91 return (ch[7] & 0x7f) == 0x7f && ch[6] == 0xf0; |
|
92 } |
|
93 } |
|
94 |
|
95 static inline bool qIsNaN(double d) |
|
96 { |
|
97 uchar *ch = (uchar *)&d; |
|
98 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
99 return (ch[0] & 0x7f) == 0x7f && ch[1] > 0xf0; |
|
100 } else { |
|
101 return (ch[7] & 0x7f) == 0x7f && ch[6] > 0xf0; |
|
102 } |
|
103 } |
|
104 |
|
105 static inline bool qIsFinite(double d) |
|
106 { |
|
107 uchar *ch = (uchar *)&d; |
|
108 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
109 return (ch[0] & 0x7f) != 0x7f || (ch[1] & 0xf0) != 0xf0; |
|
110 } else { |
|
111 return (ch[7] & 0x7f) != 0x7f || (ch[6] & 0xf0) != 0xf0; |
|
112 } |
|
113 } |
|
114 |
|
115 static inline bool qIsInf(float d) |
|
116 { |
|
117 uchar *ch = (uchar *)&d; |
|
118 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
119 return (ch[0] & 0x7f) == 0x7f && ch[1] == 0x80; |
|
120 } else { |
|
121 return (ch[3] & 0x7f) == 0x7f && ch[2] == 0x80; |
|
122 } |
|
123 } |
|
124 |
|
125 static inline bool qIsNaN(float d) |
|
126 { |
|
127 uchar *ch = (uchar *)&d; |
|
128 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
129 return (ch[0] & 0x7f) == 0x7f && ch[1] > 0x80; |
|
130 } else { |
|
131 return (ch[3] & 0x7f) == 0x7f && ch[2] > 0x80; |
|
132 } |
|
133 } |
|
134 |
|
135 static inline bool qIsFinite(float d) |
|
136 { |
|
137 uchar *ch = (uchar *)&d; |
|
138 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { |
|
139 return (ch[0] & 0x7f) != 0x7f || (ch[1] & 0x80) != 0x80; |
|
140 } else { |
|
141 return (ch[3] & 0x7f) != 0x7f || (ch[2] & 0x80) != 0x80; |
|
142 } |
|
143 } |
|
144 |
|
145 #endif // QNUMERIC_P_H |