Library contents

Java Math.IEEEremainder

Subtract the nearest whole multiple of one turn to produce a signed angular offset.

A simple example

Math.IEEEremainder

  1. Start with 7 and 4
  2. Do this Use the nearest quotient 2
  3. Result −1
Seven minus two times four is −1. The nearest integer quotient determines this remainder.
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        System.out.println(Math.IEEEremainder(7.0, 4.0));
    }
}
Output
-1.0

Syntax

Java syntax
Math.IEEEremainder(angle, turn)
JDK 21 method signatures (1)
public static double IEEEremainder(double f1, double f2)
Run these examples in Java

Save one example at a time as Main.java. Use JDK 21.

java Main.java

Find a short signed turn

A navigation dial can describe the same final heading using turns in either direction. Reduce the difference to a short signed turn so the operator sees which way to rotate.

From the programdouble angle = 350.0
Result-10.000
Main.java

class Main {
    public static void main(String[] args) throws Exception {
        double angle = 350.0;
        double turn = 360.0;

        System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.IEEEremainder(angle, turn)));
    }
}
Output
-10.000

The closest multiple of 360 to 350 is 360, leaving minus ten degrees.

Advertisements

Correct a camera pan

A turntable records a pan of 355 degrees. The camera operator wants the equivalent signed correction around the nearest complete turn.

Given355 · 360
Worked result-5 degrees

Using 355 · 360 gives -5 degrees for this measurement.

Read a compass after one turn

A simulation produces an angle of 380 degrees. The display subtracts the nearest multiple of 360 to report the small signed offset.

Given380 · 360
Worked result20 degrees

Using 380 · 360 gives 20 degrees for this measurement.

What to watch for

At an exact halfway quotient, the nearest even quotient is used. The result may be negative.

Documentation for Math.IEEEremainder