tweetcast/client/lib/websocket-js/flash-src/third-party/com/hurlant/math/ClassicReduction.as
changeset 311 13702105c5ee
parent 310 526d3e411736
child 312 f8336354d107
child 314 0f1e6ce19b6d
equal deleted inserted replaced
310:526d3e411736 311:13702105c5ee
     1 package 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 }