Skip to content

Commit 5b92405

Browse files
authored
Merge pull request #2238 from mgreter/bugfix/issue-2236
Fix modulo operation to behave as ruby sass
2 parents 0443d7f + b6c39e1 commit 5b92405

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/eval.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ namespace Sass {
3131
inline double sub(double x, double y) { return x - y; }
3232
inline double mul(double x, double y) { return x * y; }
3333
inline double div(double x, double y) { return x / y; } // x/0 checked by caller
34-
inline double mod(double x, double y) { return std::abs(std::fmod(x, y)); } // x/0 checked by caller
34+
inline double mod(double x, double y) { // x/0 checked by caller
35+
if ((x > 0 && y < 0) || (x < 0 && y > 0)) {
36+
double ret = std::fmod(x, y);
37+
return ret ? ret + y : ret;
38+
} else {
39+
return std::fmod(x, y);
40+
}
41+
}
3542
typedef double (*bop)(double, double);
3643
bop ops[Sass_OP::NUM_OPS] = {
3744
0, 0, // and, or

0 commit comments

Comments
 (0)