Skip to content

Commit 10d2d30

Browse files
committed
Implement lt operator for Number class
1 parent 9ed0ded commit 10d2d30

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ast.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,23 @@ namespace Sass {
11861186
return operator==(&rhs);
11871187
}
11881188

1189+
bool Number::operator< (Number* rhs) const
1190+
{
1191+
Number tmp_r(*rhs);
1192+
tmp_r.normalize(find_convertible_unit());
1193+
string l_unit(unit());
1194+
string r_unit(tmp_r.unit());
1195+
if (!l_unit.empty() && !r_unit.empty() && unit() != tmp_r.unit()) {
1196+
error("cannot compare numbers with incompatible units", pstate());
1197+
}
1198+
return value() < tmp_r.value();
1199+
}
1200+
1201+
bool Number::operator< (Number& rhs) const
1202+
{
1203+
return operator<(&rhs);
1204+
}
1205+
11891206
bool String_Quoted::operator== (Expression* rhs) const
11901207
{
11911208
if (String_Quoted* qstr = dynamic_cast<String_Quoted*>(rhs)) {

ast.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,8 @@ namespace Sass {
11921192
// useful for making one number compatible with another
11931193
string find_convertible_unit() const;
11941194

1195+
virtual bool operator< (Number& rhs) const;
1196+
virtual bool operator< (Number* rhs) const;
11951197
virtual bool operator== (Expression& rhs) const;
11961198
virtual bool operator== (Expression* rhs) const;
11971199

0 commit comments

Comments
 (0)