aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi/qjsprimitivevalue.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsapi/qjsprimitivevalue.h')
-rw-r--r--src/qml/jsapi/qjsprimitivevalue.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsprimitivevalue.h b/src/qml/jsapi/qjsprimitivevalue.h
index f9cc9f3089..5a82175783 100644
--- a/src/qml/jsapi/qjsprimitivevalue.h
+++ b/src/qml/jsapi/qjsprimitivevalue.h
@@ -48,6 +48,7 @@
#include <QtCore/qvariant.h>
#include <variant>
+#include <cmath>
QT_BEGIN_NAMESPACE
@@ -296,6 +297,33 @@ public:
return operate<DivOperators>(lhs, rhs);
}
+ friend inline QJSPrimitiveValue operator%(const QJSPrimitiveValue &lhs,
+ const QJSPrimitiveValue &rhs)
+ {
+ switch (lhs.type()) {
+ case Null:
+ case Boolean:
+ case Integer:
+ switch (rhs.type()) {
+ case Boolean:
+ case Integer: {
+ const int leftInt = lhs.toInteger();
+ const int rightInt = rhs.toInteger();
+ if (leftInt >= 0 && rightInt > 0)
+ return leftInt % rightInt;
+ Q_FALLTHROUGH();
+ }
+ default:
+ break;
+ }
+ Q_FALLTHROUGH();
+ default:
+ break;
+ }
+
+ return std::fmod(lhs.toDouble(), rhs.toDouble());
+ }
+
constexpr bool strictlyEquals(const QJSPrimitiveValue &other) const
{
const Type myType = type();