Skip to main content
Commonmark migration
Source Link

#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:

Try it here.

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

#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:

Try it here.

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

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:

Try it here.

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
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

#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 (sourcesource). 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:

Try it here.

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

#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:

Try it here.

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

#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:

Try it here.

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
Rollback to Revision 3
Source Link
Kevin Cruijssen
  • 136.9k
  • 14
  • 158
  • 399

#Java 7, 44 43 7643 bytes

Crossed out 44 is still regular 44 ;(

+33 bytes for bug-fixing rule "If you take the input in degrees, the output must also be in degrees; if you take it in radians, the output must be in radians too."..

float c(float n){return(n%=360)<0?n+360:n;}int c(int n){return(int)c(1f*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

int c(int n){          // Separate method with integer input and integer return-type
  return(int)c(1f*n);  // Use the float-method, but return as integer
}                      // End of method

Test code:

Try it here.Try it here.

class M{
  static float c(float n){return(n%=360)<0?n+360:n;}int c(int n){return(int)c(1f*n);}

  public static void main(String[] a){
    M m = new M();
    System.out.print(m.c(745) + "; ");
    System.out.print(m.c(1728) + "; ");
    System.out.print(m.c(90) + "; ");
    System.out.print(m.c(0) + "; ");
    System.out.print(m.c(360) + "; ");
    System.out.print(m.c(-50) + "; ");
    System.out.print(m.c(-543.21f));
  }
}

Output:

25;25.0; 288;288.0; 90;90.0; 0.0; 0.0; 310;310.0; 176.78998

#Java 7, 44 43 76 bytes

Crossed out 44 is still regular 44 ;(

+33 bytes for bug-fixing rule "If you take the input in degrees, the output must also be in degrees; if you take it in radians, the output must be in radians too."..

float c(float n){return(n%=360)<0?n+360:n;}int c(int n){return(int)c(1f*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

int c(int n){          // Separate method with integer input and integer return-type
  return(int)c(1f*n);  // Use the float-method, but return as integer
}                      // End of method

Test code:

Try it here.

class M{
  float c(float n){return(n%=360)<0?n+360:n;}int c(int n){return(int)c(1f*n);}

  public static void main(String[] a){
    M m = new M();
    System.out.print(m.c(745) + "; ");
    System.out.print(m.c(1728) + "; ");
    System.out.print(m.c(90) + "; ");
    System.out.print(m.c(0) + "; ");
    System.out.print(m.c(360) + "; ");
    System.out.print(m.c(-50) + "; ");
    System.out.print(m.c(-543.21f));
  }
}

Output:

25; 288; 90; 0; 0; 310; 176.78998

#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:

Try it here.

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
+33 by bug-fixing rule about not returning decimal for integer input
Source Link
Kevin Cruijssen
  • 136.9k
  • 14
  • 158
  • 399
Loading
Changed `n=n%` to `n%=` for -1 byte
Source Link
Kevin Cruijssen
  • 136.9k
  • 14
  • 158
  • 399
Loading
added 1378 characters in body
Source Link
Kevin Cruijssen
  • 136.9k
  • 14
  • 158
  • 399
Loading
Source Link
Kevin Cruijssen
  • 136.9k
  • 14
  • 158
  • 399
Loading