Permalink
Browse files

Four4Sample - Fix overflow of denominator in addition

  • Loading branch information...
bobbymcr committed Mar 20, 2018
1 parent 5356f5c commit da754d4a95bf9295bb09f69e8cdb4f13dc7f253a
Showing with 8 additions and 2 deletions.
  1. +1 −0 projects/Four4Sample/Four4.Test/EvalTest.cs
  2. +7 −2 projects/Four4Sample/Four4/Number.cs
@@ -173,6 +173,7 @@ public void ExpressionsWith3(string input, string result)
[InlineData(".5 5 5 * 5 + ^ 5 5 - .5 - *")]
[InlineData(".5 55 5 ^ / 5 +")]
[InlineData("4 ! 4 ! 4 R / ! - .4 +")]
[InlineData(".5 55 5 ^ / .5 55 5 ^ / +")]
public void BadExpressions(string input)
{
Test(input, "NaN");
@@ -50,8 +50,13 @@ public Number(int num, int denom)
return NaN;
}
int d = left.denom * right.denom;
return new Number((int)nr, d);
double dr = (double)left.denom * right.denom;
if (dr > int.MaxValue)
{
return NaN;
}
return new Number((int)nr, (int)dr);
}
public static Number operator -(Number left, Number right)

0 comments on commit da754d4

Please sign in to comment.