Guest User

Untitled

a guest
Jan 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4. minRotationIEEERemainder(4095, 1); // expect +2
  5. minRotationIEEERemainder(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions
  6. minRotationIEEERemainder(-1024, 1024); // expect +/- 2048
  7. minRotationIEEERemainder(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions
  8. minRotationIEEERemainder(2730, 1365); // 240 -> 120 expect -120 (-1365)
  9. minRotationIEEERemainder(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365)
  10.  
  11. minRotationMaskCurrent(4095, 1); // expect +2
  12. minRotationMaskCurrent(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions
  13. minRotationMaskCurrent(-1024, 1024); // expect +/- 2048
  14. minRotationMaskCurrent(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions
  15. minRotationMaskCurrent(2730, 1365); // 240 -> 120 expect -120 (-1365)
  16. minRotationMaskCurrent(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365)
  17.  
  18. minRotationMaskError(4095, 1); // expect +2
  19. minRotationMaskError(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions
  20. minRotationMaskError(-1024, 1024); // expect +/- 2048
  21. minRotationMaskError(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions
  22. minRotationMaskError(2730, 1365); // 240 -> 120 expect -120 (-1365)
  23. minRotationMaskError(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365)
  24. }
  25.  
  26. static void minRotationIEEERemainder(int current, int desired) {
  27. double rotation = Math.IEEEremainder(desired - current, 0x1000);
  28. System.out.printf(
  29. "IEEERemainder: current = %7d, desired = %7d, rotation = %7.0f%n",
  30. current, desired, rotation);
  31. }
  32.  
  33. static void minRotationMaskCurrent(int current, int desired) {
  34. int rotation = desired - (current & 0xFFF);
  35. System.out.printf(
  36. "Mask Current: current = %7d, desired = %7d, rotation = %7d%n",
  37. current, desired, rotation);
  38. }
  39.  
  40. static void minRotationMaskError(int current, int desired) {
  41. int rotation = (desired - current) & 0xFFF;
  42. System.out.printf(
  43. "Mask Error: current = %7d, desired = %7d, rotation = %7d%n",
  44. current, desired, rotation);
  45. }
  46. }
Add Comment
Please, Sign In to add comment