Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4math_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QMLJS_MATH_H
4#define QMLJS_MATH_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <qglobal.h>
18
19#include <private/qv4staticvalue_p.h>
20#include <QtCore/qnumeric.h>
21#include <QtCore/private/qnumeric_p.h>
22#include <cmath>
23
24#if defined(Q_CC_GNU)
25#define QMLJS_READONLY __attribute((const))
26#else
27#define QMLJS_READONLY
28#endif
29
31
32namespace QV4 {
33
34static inline QMLJS_READONLY ReturnedValue add_int32(int a, int b)
35{
36 int result;
38 return StaticValue::fromDouble(static_cast<double>(a) + b).asReturnedValue();
39 return StaticValue::fromInt32(result).asReturnedValue();
40}
41
42static inline QMLJS_READONLY ReturnedValue sub_int32(int a, int b)
43{
44 int result;
46 return StaticValue::fromDouble(static_cast<double>(a) - b).asReturnedValue();
47 return StaticValue::fromInt32(result).asReturnedValue();
48}
49
50static inline QMLJS_READONLY ReturnedValue mul_int32(int a, int b)
51{
52 int result;
54 return StaticValue::fromDouble(static_cast<double>(a) * b).asReturnedValue();
55 // need to handle the case where one number is negative and the other 0 ==> -0
56 if (((a < 0) xor (b < 0)) && (result == 0))
57 return StaticValue::fromDouble(-0.0).asReturnedValue();
58 return StaticValue::fromInt32(result).asReturnedValue();
59}
60
61}
62
64
65#ifdef QMLJS_READONLY
66#undef QMLJS_READONLY
67#endif
68
69#endif // QMLJS_MATH_H
Combined button and popup list for selecting options.
static QMLJS_READONLY ReturnedValue mul_int32(int a, int b)
Definition qv4math_p.h:50
static QMLJS_READONLY ReturnedValue add_int32(int a, int b)
Definition qv4math_p.h:34
quint64 ReturnedValue
static QMLJS_READONLY ReturnedValue sub_int32(int a, int b)
Definition qv4math_p.h:42
#define Q_UNLIKELY(x)
std::enable_if_t< std::is_unsigned_v< T >, bool > qAddOverflow(T v1, T v2, T *r)
Definition qnumeric.h:113
std::enable_if_t< std::is_unsigned_v< T >, bool > qSubOverflow(T v1, T v2, T *r)
Definition qnumeric.h:153
std::enable_if_t< std::is_unsigned_v< T >||std::is_signed_v< T >, bool > qMulOverflow(T v1, T v2, T *r)
Definition qnumeric.h:182
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint64EXT * result
[6]
#define QMLJS_READONLY
Definition qv4math_p.h:27
static StaticValue fromDouble(double d)
static constexpr StaticValue fromInt32(int i)