PageRenderTime 76ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/math/ClassicReduction.as

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