src/corelib/global/qnumeric_p.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtCore module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QNUMERIC_P_H
00025 #define QNUMERIC_P_H
00026 
00027 //
00028 //  W A R N I N G
00029 //  -------------
00030 //
00031 // This file is not part of the Qt API.  It exists purely as an
00032 // implementation detail.  This header file may change from version to
00033 // version without notice, or even be removed.
00034 //
00035 // We mean it.
00036 //
00037 
00038 #include "QtCore/qglobal.h"
00039 
00040 static const unsigned char qt_be_inf_bytes[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 };
00041 static const unsigned char qt_le_inf_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
00042 static inline double qtInf()
00043 {
00044     return *reinterpret_cast<const double *>(QSysInfo::ByteOrder == QSysInfo::BigEndian ? qt_be_inf_bytes : qt_le_inf_bytes);
00045 }
00046 #define Q_INFINITY (::qtInf())
00047 
00048 // Signaling NAN
00049 static const unsigned char qt_be_snan_bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 };
00050 static const unsigned char qt_le_snan_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
00051 static inline double qtSnan()
00052 {
00053     return *reinterpret_cast<const double *>(QSysInfo::ByteOrder == QSysInfo::BigEndian ? qt_be_snan_bytes : qt_le_snan_bytes);
00054 }
00055 #define Q_SNAN (::qtSnan())
00056 
00057 // Quiet NAN
00058 static const unsigned char qt_be_qnan_bytes[] = { 0xff, 0xf8, 0, 0, 0, 0, 0, 0 };
00059 static const unsigned char qt_le_qnan_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0xff };
00060 static inline double qtQnan()
00061 {
00062     return *reinterpret_cast<const double *>(QSysInfo::ByteOrder == QSysInfo::BigEndian ? qt_be_qnan_bytes : qt_le_qnan_bytes);
00063 }
00064 #define Q_QNAN (::qtQnan())
00065 
00066 static inline bool qIsInf(double d)
00067 {
00068     uchar *ch = (uchar *)&d;
00069     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
00070         return (ch[0] & 0x7f) == 0x7f && ch[1] == 0xf0;
00071     } else {
00072         return (ch[7] & 0x7f) == 0x7f && ch[6] == 0xf0;
00073     }
00074 }
00075 
00076 static inline bool qIsNan(double d)
00077 {
00078     uchar *ch = (uchar *)&d;
00079     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
00080         return (ch[0] & 0x7f) == 0x7f && ch[1] > 0xf0;
00081     } else {
00082         return (ch[7] & 0x7f) == 0x7f && ch[6] > 0xf0;
00083     }
00084 }
00085 
00086 static inline bool qIsFinite(double d)
00087 {
00088     uchar *ch = (uchar *)&d;
00089     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
00090         return (ch[0] & 0x7f) != 0x7f || (ch[1] & 0xf0) != 0xf0;
00091     } else {
00092         return (ch[7] & 0x7f) != 0x7f || (ch[6] & 0xf0) != 0xf0;
00093     }
00094 }
00095 
00096 static inline bool qIsInf(float d)
00097 {
00098     uchar *ch = (uchar *)&d;
00099     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
00100         return (ch[0] & 0x7f) == 0x7f && ch[1] == 0x80;
00101     } else {
00102         return (ch[3] & 0x7f) == 0x7f && ch[2] == 0x80;
00103     }
00104 }
00105 
00106 static inline bool qIsNan(float d)
00107 {
00108     uchar *ch = (uchar *)&d;
00109     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
00110         return (ch[0] & 0x7f) == 0x7f && ch[1] > 0x80;
00111     } else {
00112         return (ch[3] & 0x7f) == 0x7f && ch[2] > 0x80;
00113     }
00114 }
00115 
00116 static inline bool qIsFinite(float d)
00117 {
00118     uchar *ch = (uchar *)&d;
00119     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
00120         return (ch[0] & 0x7f) != 0x7f || (ch[1] & 0x80) != 0x80;
00121     } else {
00122         return (ch[3] & 0x7f) != 0x7f || (ch[2] & 0x80) != 0x80;
00123     }
00124 }
00125 
00126 #endif // QNUMERIC_P_H

Generated on Thu Mar 15 11:53:09 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1