| author | Raphael Velt <raph.velt@gmail.com> |
| Thu, 06 Oct 2011 12:39:29 +0200 | |
| changeset 306 | 70c9688a1486 |
| parent 305 | tweetcast/client/lib/gimite-web-socket-js-55ae639/flash-src/third-party/com/hurlant/math/ClassicReduction.as@436a31d11f1d |
| permissions | -rwxr-xr-x |
|
305
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
1 |
package com.hurlant.math |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
2 |
{ |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
3 |
use namespace bi_internal; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
4 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
5 |
/** |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
6 |
* Modular reduction using "classic" algorithm |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
7 |
*/ |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
8 |
internal class ClassicReduction implements IReduction |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
9 |
{ |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
10 |
private var m:BigInteger; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
11 |
public function ClassicReduction(m:BigInteger) { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
12 |
this.m = m; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
13 |
} |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
14 |
public function convert(x:BigInteger):BigInteger { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
15 |
if (x.s<0 || x.compareTo(m)>=0) { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
16 |
return x.mod(m); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
17 |
} |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
18 |
return x; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
19 |
} |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
20 |
public function revert(x:BigInteger):BigInteger { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
21 |
return x; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
22 |
} |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
23 |
public function reduce(x:BigInteger):void { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
24 |
x.divRemTo(m, null,x); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
25 |
} |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
26 |
public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger):void { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
27 |
x.multiplyTo(y,r); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
28 |
reduce(r); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
29 |
} |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
30 |
public function sqrTo(x:BigInteger, r:BigInteger):void { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
31 |
x.squareTo(r); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
32 |
reduce(r); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
33 |
} |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
34 |
} |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
35 |
} |