Groovy Math.IEEEremainder
Subtract the nearest whole multiple of one turn to produce a signed angular offset.
A simple example
Math.IEEEremainder
- Start with 7 and 4
- Do this Use the nearest quotient 2
- Result −1
println(Math.IEEEremainder(7.0d, 4.0d))
-1.0
Syntax
Math.IEEEremainder(angle, turn)
Run these examples in Groovy
Save one example at a time as Lesson.groovy. Use Groovy 4 on JDK 21.
groovy Lesson.groovyFind 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.
double angle = 350.0
double turn = 360.0
System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.IEEEremainder(angle, turn)))
-10.000
The closest multiple of 360 to 350 is 360, leaving minus ten degrees.
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.
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.
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.