/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/math/ClassicReduction.as
ActionScript | 35 lines | 31 code | 1 blank | 3 comment | 2 complexity | 023e296ce91264fe2440894e5fee968c 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}