Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- minRotationIEEERemainder(4095, 1); // expect +2
- minRotationIEEERemainder(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions
- minRotationIEEERemainder(-1024, 1024); // expect +/- 2048
- minRotationIEEERemainder(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions
- minRotationIEEERemainder(2730, 1365); // 240 -> 120 expect -120 (-1365)
- minRotationIEEERemainder(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365)
- minRotationMaskCurrent(4095, 1); // expect +2
- minRotationMaskCurrent(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions
- minRotationMaskCurrent(-1024, 1024); // expect +/- 2048
- minRotationMaskCurrent(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions
- minRotationMaskCurrent(2730, 1365); // 240 -> 120 expect -120 (-1365)
- minRotationMaskCurrent(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365)
- minRotationMaskError(4095, 1); // expect +2
- minRotationMaskError(10 * 0x1000 + 4095, 1); // same, plus 10 revolutions
- minRotationMaskError(-1024, 1024); // expect +/- 2048
- minRotationMaskError(10 * 0x1000 - 1024, 1024); // same, plus 10 revolutions
- minRotationMaskError(2730, 1365); // 240 -> 120 expect -120 (-1365)
- minRotationMaskError(10 * 0x1000 + 2730, 1365); // 240 -> 120 expect -120 (-1365)
- }
- static void minRotationIEEERemainder(int current, int desired) {
- double rotation = Math.IEEEremainder(desired - current, 0x1000);
- System.out.printf(
- "IEEERemainder: current = %7d, desired = %7d, rotation = %7.0f%n",
- current, desired, rotation);
- }
- static void minRotationMaskCurrent(int current, int desired) {
- int rotation = desired - (current & 0xFFF);
- System.out.printf(
- "Mask Current: current = %7d, desired = %7d, rotation = %7d%n",
- current, desired, rotation);
- }
- static void minRotationMaskError(int current, int desired) {
- int rotation = (desired - current) & 0xFFF;
- System.out.printf(
- "Mask Error: current = %7d, desired = %7d, rotation = %7d%n",
- current, desired, rotation);
- }
- }
Add Comment
Please, Sign In to add comment