PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/flash-src/third-party/com/hurlant/math/ClassicReduction.as

http://github.com/gimite/web-socket-js
ActionScript | 35 lines | 31 code | 1 blank | 3 comment | 2 complexity | 5c569ab3d2c2349d45214fd8ac38b32e MD5 | raw file
 1package com.hurlant.math
 2{
 3	use namespace bi_internal;
 4	
 5	/**
 6	 * Modular reduction using "classic" algorithm
 7	 */
 8	internal class ClassicReduction implements IReduction
 9	{
10		private var m:BigInteger;
11		public function ClassicReduction(m:BigInteger) {
12			this.m = m;
13		}
14		public function convert(x:BigInteger):BigInteger {
15			if (x.s<0 || x.compareTo(m)>=0) {
16				return x.mod(m);
17			}
18			return x;
19		}
20		public function revert(x:BigInteger):BigInteger {
21			return x;
22		}
23		public function reduce(x:BigInteger):void {
24			x.divRemTo(m, null,x);
25		}
26		public function mulTo(x:BigInteger, y:BigInteger, r:BigInteger):void {
27			x.multiplyTo(y,r);
28			reduce(r);
29		}
30		public function sqrTo(x:BigInteger, r:BigInteger):void {
31			x.squareTo(r);
32			reduce(r);
33		}
34	}
35}