Skip to content

Commit 6f68ded

Browse files
committed
Value: Add 'add' method
1 parent b6d4c3e commit 6f68ded

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/scratch/value.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,23 @@ std::u16string Value::toUtf16() const
232232
return utf8::utf8to16(toString());
233233
}
234234

235+
/*! Adds the given value to the value. */
236+
void Value::add(const Value &v)
237+
{
238+
if ((m_isInfinity && v.m_isNegativeInfinity) || (m_isNegativeInfinity && v.m_isInfinity)) {
239+
m_isInfinity = false;
240+
m_isNegativeInfinity = false;
241+
m_isNaN = true;
242+
} else if (m_isInfinity || v.m_isInfinity) {
243+
m_type = Type::Special;
244+
m_isInfinity = true;
245+
} else if (m_isNegativeInfinity || v.m_isNegativeInfinity) {
246+
m_type = Type::Special;
247+
m_isNegativeInfinity = true;
248+
}
249+
m_value = toDouble() + v.toDouble();
250+
}
251+
235252
bool Value::stringsEqual(std::u16string s1, std::u16string s2)
236253
{
237254
std::transform(s1.begin(), s1.end(), s1.begin(), ::tolower);

src/scratch/value.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class LIBSCRATCHCPP_EXPORT Value
5555
std::string toString() const;
5656
std::u16string toUtf16() const;
5757

58+
void add(const Value &v);
59+
5860
inline const Value &operator=(float v)
5961
{
6062
m_type = Type::Number;

0 commit comments

Comments
 (0)