public void BigInt_Abs_ReturnsOriginalInstanceIfNotInitialized() { BigInt uninitialized = default(BigInt); BigInt absForUninitialized = uninitialized.Abs(); Assert.AreEqual(uninitialized, absForUninitialized); }
public void AbsTest() { BigInt a = new BigInt(-123456); BigInt e = new BigInt(123456); Assert.AreEqual(e, a.Abs()); }
private void KeepSign() { if (Numerator * Denominator < (BigInt)0) { Denominator = BigInt.Abs(Denominator); Numerator = BigInt.Abs(Numerator) * ((BigInt)(-1)); } }
private Point SimpleMultiply(Point p, BigInt k) { if (!(this.field.IsValidElement(p.X)) || !(this.field.IsValidElement(p.Y)) ) { throw new ArgumentException("The input point must be taken over the field."); } if (p.IsInfinity()) { return(p); } if (k.Equals(BigInt.ZERO)) { return(Point.INFINITY); } if (k.Equals(BigInt.ONE)) { return(p); } if (k.Signum() == -1) { k = k.Abs(); p = this.Negate(p); } sbyte[] ba = k.ToByteArray(); int degree = ByteArrayUtil.DegreeOf(ba) - 1; Point x = p; for (int i = degree; i >= 0; i--) { x = this.Dbl(x); if (ByteArrayUtil.GetBitByDegree(i, ba)) { x = this.Add(p, x); } } return(x); }
//multiplication using Jacobian coordinates public JacobPoint JMultiplyMut(Point p, BigInt k) { if (!(this.field.IsValidElement(p.X)) || !(this.field.IsValidElement(p.Y))) { throw new ArgumentException("The input point must be taken over the field."); } if (p.IsInfinity()) { return(this.AToJ(p)); } if (k.Equals(BigInt.ZERO)) { return(JacobPoint.INFINITY); } if (k.Equals(BigInt.ONE)) { return(this.AToJ(p)); } if (k.Signum() == -1) { k = k.Abs(); p = this.Negate(p); } //byte [] ba =k.toByteArray(); int degree = k.BitLength() - 2; JacobPoint result = this.AToJ(p); for (int i = degree; i >= 0; i--) { this.JDblMut(result); if (k.TestBit(i)) ///AQUI TE QUEDASTE IMPLEMENTAR TESTBIT { this.JAddMut(result, p); } } return(result); }