#Java 7, 44 43 bytes
Java 7, 44 43 bytes
Crossed out 44 is still regular 44 ;(
float c(float n){return(n%=360)<0?n+360:n;}
Explanation:
Java uses remainder instead of actual modulo for negative numbers (source). So we'll have to manually fix the negative cases.
float c(float n){ // Method with float input and float return-type
return(n%=360)<0? // If input mod-360 is negative
n+360 // Return input mod-360 + 360
: // Else:
n; // Return input mod-360
} // End of method
Test code:
class M{
static float c(float n){return(n%=360)<0?n+360:n;}
public static void main(String[] a){
System.out.print(c(745) + "; ");
System.out.print(c(1728) + "; ");
System.out.print(c(90) + "; ");
System.out.print(c(0) + "; ");
System.out.print(c(360) + "; ");
System.out.print(c(-50) + "; ");
System.out.print(c(-543.21f));
}
}
Output:
25.0; 288.0; 90.0; 0.0; 0.0; 310.0; 176.78998