深入学习java源码之Math.toRadians()与 Math.toDegrees()
strictfp关键字, 即 strict float point (精确浮点)。 strictfp 的意思是FP-strict,也就是说精确浮点的意思。在Java虚拟机进行浮点运算时,如果没有指定strictfp关键字时,Java的编译器以及运 行环境在对浮点运算的表达式是采取一种近似于我行我素的行为来完成这些操作,以致于得到的结果往往无法令你满意。而一旦使用了strictfp来声明一个 类、接口或者方法时,那么所声明的范围内Java的编译器以及运行环境会完全依照浮点规范IEEE-754来执行。因此如果你想让你的浮点运算更加精确, 而且不会因为不同的硬件平台所执行的结果不一致的话,那就请用关键字strictfp。 如果你想让你的浮点运算更加精确,而且不会因为不同的硬件平台所执行的结果不一致的话,可以用关键字strictfp.
Modifier and TypeMethod and Descriptionstatic double
toDegrees(double angrad)
将以弧度测量的角度转换为以度为单位的近似等效角度。
static double
toRadians(double angdeg)
将以度为单位的角度转换为以弧度测量的大致相等的角度。
java源码
public final class Math {
private Math() {}
public static final double E = 2.7182818284590452354;
public static final double PI = 3.14159265358979323846;
public static double toRadians(double angdeg) {
return angdeg / 180.0 * PI;
}
public static double toDegrees(double angrad) {
return angrad * 180.0 / PI;
}
}
public final class StrictMath {
private StrictMath() {}
public static final double E = 2.7182818284590452354;
public static final double PI = 3.14159265358979323846;
public static strictfp double toRadians(double angdeg) {
// Do not delegate to Math.toRadians(angdeg) because
// this method has the strictfp modifier.
return angdeg / 180.0 * PI;
}
public static strictfp double toDegrees(double angrad) {
// Do not delegate to Math.toDegrees(angrad) because
// this method has the strictfp modifier.
return angrad * 180.0 / PI;
}
}