Skip to content

Commit 74f769f

Browse files
committed
Value: Add mod method
1 parent 39bf7e7 commit 74f769f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/scratch/value.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ class LIBSCRATCHCPP_EXPORT Value : public ValueVariant
239239
*this = toDouble() / v.toDouble();
240240
}
241241

242+
/*! Replaces the value with modulo of the value and the given value. */
243+
inline void mod(const Value &v)
244+
{
245+
if ((v == 0) || (m_type == Type::Infinity || m_type == Type::NegativeInfinity))
246+
m_type = Type::NaN;
247+
else if (v.m_type == Type::Infinity || v.m_type == Type::NegativeInfinity) {
248+
return;
249+
}
250+
*this = fmod(toDouble(), v.toDouble());
251+
}
252+
242253
inline const Value &operator=(float v)
243254
{
244255
m_type = Type::Number;

0 commit comments

Comments
 (0)