source: trunk/src/corelib/kernel/qmath.h@ 730

Last change on this file since 730 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 7.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QMATH_H
43#define QMATH_H
44
45#include <math.h>
46
47#include <QtCore/qglobal.h>
48
49#ifdef Q_OS_SYMBIAN
50# include <e32math.h>
51#endif
52
53QT_BEGIN_HEADER
54
55QT_BEGIN_NAMESPACE
56
57QT_MODULE(Core)
58
59#define QT_SINE_TABLE_SIZE 256
60
61extern Q_CORE_EXPORT const qreal qt_sine_table[QT_SINE_TABLE_SIZE];
62
63inline int qCeil(qreal v)
64{
65#ifdef QT_USE_MATH_H_FLOATS
66 if (sizeof(qreal) == sizeof(float))
67 return int(ceilf(float(v)));
68 else
69#endif
70 return int(ceil(v));
71}
72
73inline int qFloor(qreal v)
74{
75#ifdef QT_USE_MATH_H_FLOATS
76 if (sizeof(qreal) == sizeof(float))
77 return int(floorf(float(v)));
78 else
79#endif
80 return int(floor(v));
81}
82
83inline qreal qFabs(qreal v)
84{
85#ifdef QT_USE_MATH_H_FLOATS
86 if(sizeof(qreal) == sizeof(float))
87 return fabsf(float(v));
88 else
89#endif
90 return fabs(v);
91}
92
93inline qreal qSin(qreal v)
94{
95#ifdef Q_OS_SYMBIAN
96 TReal sin_v;
97 Math::Sin(sin_v, static_cast<TReal>(v));
98 return static_cast<qreal>(sin_v);
99#else
100# ifdef QT_USE_MATH_H_FLOATS
101 if (sizeof(qreal) == sizeof(float))
102 return sinf(float(v));
103 else
104# endif
105 return sin(v);
106#endif
107}
108
109inline qreal qCos(qreal v)
110{
111#ifdef Q_OS_SYMBIAN
112 TReal cos_v;
113 Math::Cos(cos_v, static_cast<TReal>(v));
114 return static_cast<qreal>(cos_v);
115#else
116# ifdef QT_USE_MATH_H_FLOATS
117 if (sizeof(qreal) == sizeof(float))
118 return cosf(float(v));
119 else
120# endif
121 return cos(v);
122#endif
123}
124
125inline qreal qTan(qreal v)
126{
127#ifdef Q_OS_SYMBIAN
128 TReal tan_v;
129 Math::Tan(tan_v, static_cast<TReal>(v));
130 return static_cast<qreal>(tan_v);
131#else
132# ifdef QT_USE_MATH_H_FLOATS
133 if (sizeof(qreal) == sizeof(float))
134 return tanf(float(v));
135 else
136# endif
137 return tan(v);
138#endif
139}
140
141inline qreal qAcos(qreal v)
142{
143#ifdef Q_OS_SYMBIAN
144 TReal acos_v;
145 Math::ACos(acos_v, static_cast<TReal>(v));
146 return static_cast<qreal>(acos_v);
147#else
148# ifdef QT_USE_MATH_H_FLOATS
149 if (sizeof(qreal) == sizeof(float))
150 return acosf(float(v));
151 else
152# endif
153 return acos(v);
154#endif
155}
156
157inline qreal qAsin(qreal v)
158{
159#ifdef Q_OS_SYMBIAN
160 TReal asin_v;
161 Math::ASin(asin_v, static_cast<TReal>(v));
162 return static_cast<qreal>(asin_v);
163#else
164# ifdef QT_USE_MATH_H_FLOATS
165 if (sizeof(qreal) == sizeof(float))
166 return asinf(float(v));
167 else
168# endif
169 return asin(v);
170#endif
171}
172
173inline qreal qAtan(qreal v)
174{
175#ifdef Q_OS_SYMBIAN
176 TReal atan_v;
177 Math::ATan(atan_v, static_cast<TReal>(v));
178 return static_cast<qreal>(atan_v);
179#else
180# ifdef QT_USE_MATH_H_FLOATS
181 if(sizeof(qreal) == sizeof(float))
182 return atanf(float(v));
183 else
184# endif
185 return atan(v);
186#endif
187}
188
189inline qreal qAtan2(qreal x, qreal y)
190{
191#ifdef Q_OS_SYMBIAN
192 TReal atan2_v;
193 Math::ATan(atan2_v, static_cast<TReal>(x), static_cast<TReal>(y));
194 return static_cast<qreal>(atan2_v);
195#else
196# ifdef QT_USE_MATH_H_FLOATS
197 if(sizeof(qreal) == sizeof(float))