mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,83 @@
|
||||
package com.hurlant.math
|
||||
{
|
||||
use namespace bi_internal;
|
||||
|
||||
internal class BarrettReduction implements IReduction
|
||||
{
|
||||
|
||||
private var m:BigInteger;
|
||||
|
||||
private var r2:BigInteger;
|
||||
|
||||
private var q3:BigInteger;
|
||||
|
||||
private var mu:BigInteger;
|
||||
|
||||
public function BarrettReduction(m:BigInteger)
|
||||
{
|
||||
super();
|
||||
this.r2 = new BigInteger();
|
||||
this.q3 = new BigInteger();
|
||||
BigInteger.ONE.dlShiftTo(2 * m.t,this.r2);
|
||||
this.mu = this.r2.divide(m);
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
public function revert(x:BigInteger) : BigInteger
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.multiplyTo(y,r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function sqrTo(x:BigInteger, r:BigInteger) : void
|
||||
{
|
||||
x.squareTo(r);
|
||||
this.reduce(r);
|
||||
}
|
||||
|
||||
public function convert(x:BigInteger) : BigInteger
|
||||
{
|
||||
var r:BigInteger = null;
|
||||
if(x.s < 0 || x.t > 2 * this.m.t)
|
||||
{
|
||||
return x.mod(this.m);
|
||||
}
|
||||
if(x.compareTo(this.m) < 0)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
r = new BigInteger();
|
||||
x.copyTo(r);
|
||||
this.reduce(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public function reduce(lx:BigInteger) : void
|
||||
{
|
||||
var x:BigInteger = lx as BigInteger;
|
||||
x.drShiftTo(this.m.t - 1,this.r2);
|
||||
if(x.t > this.m.t + 1)
|
||||
{
|
||||
x.t = this.m.t + 1;
|
||||
x.clamp();
|
||||
}
|
||||
this.mu.multiplyUpperTo(this.r2,this.m.t + 1,this.q3);
|
||||
this.m.multiplyLowerTo(this.q3,this.m.t + 1,this.r2);
|
||||
while(x.compareTo(this.r2) < 0)
|
||||
{
|
||||
x.dAddOffset(1,this.m.t + 1);
|
||||
}
|
||||
x.subTo(this.r2,x);
|
||||
while(x.compareTo(this.m) >= 0)
|
||||
{
|
||||
x.subTo(this.m,x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user