// reduce the angle
angle = angle % 360;
// force it to be the positive remainder, so that 0 <= angle < 360
angle = (angle + 360) % 360;
// force into the minimum absolute value residue class, so that -180 < angle <= 180
if (angle > 180)
angle -= 360;
More Related Contents:
- Fast algorithm to calculate n! / (q!)^r
- How to make fibonacci method? [closed]
- is there an algorithm to reverse a chosen part of a number? [closed]
- Division of integers in Java [duplicate]
- How to convert number to words in java
- How to resolve a Java Rounding Double issue [duplicate]
- How to parse a mathematical expression given as a string and return a number? [duplicate]
- Strange floating-point behaviour in a Java program [duplicate]
- Method for evaluating math expressions in Java
- Mod in Java produces negative numbers [duplicate]
- How does java do modulus calculations with negative numbers?
- Performance of Java matrix math libraries? [closed]
- How to handle very large numbers in Java without using java.math.BigInteger
- Is it possible to pass arithmetic operators to a method in java?
- MathML and Java [closed]
- How can I check if multiplying two numbers in Java will cause an overflow?
- midpoint between two latitude and longitude
- How do I get whole and fractional parts from double in JSP/Java?
- Is there a commonly used rational numbers library in Java?
- Division between integers in Java
- Calculating the angle between two lines without having to calculate the slope? (Java)
- What to do with Java BigDecimal performance?
- What’s the best practice to round a float to 2 decimals? [duplicate]
- Algorithm to generate Poisson and binomial random numbers?
- What is a non recursive solution for Fibonacci-like sequence in Java?
- What’s a good library for parsing mathematical expressions in java? [closed]
- How to rotate a vertex around a certain point?
- Java math function to convert positive int to negative and negative to positive?
- Wrong result by Java Math.pow
- Integer division in Java [duplicate]