private static void AssertEqual(int expected, Integer value)
 {
     Assert.AreEqual(expected, (int)value);
 }
Beispiel #2
0
 public Integer(Integer value)
 {
     sign = value.sign;
     this.value = value.value;
 }
Beispiel #3
0
 public Integer Add(Integer rhs)
 {
     return sign.IsOppositeOf(rhs.Sign).Accept(() => value.LessThan(rhs.value).Accept(() => new Integer(rhs.value.Subtract(value), rhs.IsPositive),
                                                                                      () => new Integer(value.Subtract(rhs.value), IsPositive)),
                                               () => new Integer(value.Add(rhs.value), IsPositive.Or(rhs.IsPositive)));
 }
Beispiel #4
0
 public Integer ShiftRight(Integer places)
 {
     return places.Sign.IsNegative.Accept(() => ShiftLeft(places.value), () => ShiftRight(places.value));
 }
Beispiel #5
0
 public Integer Subtract(Integer rhs)
 {
     return Add(rhs.Negate());
 }
Beispiel #6
0
 public Bool LessThanOrEqualTo(Integer rhs)
 {
     return rhs.IsPositive.And(IsPositive.Not)
         .Or(() => rhs.IsPositive.Accept(() => value.LessThanOrEqualTo(rhs.value),
                                         () => IsPositive.Not.And(() => rhs.value.LessThanOrEqualTo(value))));
 }
Beispiel #7
0
 public Integer Multiply(Integer rhs)
 {
     var product = value.Multiply(rhs.value);
     return new Integer(product, sign.EqualTo(rhs.sign));
 }
Beispiel #8
0
 public Bool LessThan(Integer rhs)
 {
     return rhs.IsPositive.And(IsPositive.Not)
         .Or(() => rhs.IsPositive.Accept(() => value.LessThan(rhs.value),
                                         () => IsNegative.And(() => rhs.value.LessThan(value))));
 }
Beispiel #9
0
 public Bool GreaterThanOrEqualTo(Integer rhs)
 {
     return rhs.LessThanOrEqualTo(this);
 }
Beispiel #10
0
 public Bool GreaterThan(Integer rhs)
 {
     return rhs.LessThan(this);
 }
Beispiel #11
0
 public Bool EqualTo(Integer rhs)
 {
     return sign.EqualTo(rhs.sign).And(() => value.EqualTo(rhs.value));
 }
Beispiel #12
0
 public DivisionResult<Integer> DivideBy(Integer rhs)
 {
     var result = value.DivideBy(rhs.value);
     var quotient = new Integer(result.Quotient, sign.EqualTo(rhs.sign));
     var remainder = new Integer(result.Remainder, sign);
     return DivisionResult.Create(quotient, remainder);
 }