2017.6.8 运算符

*** strictfp的作用,如何使用 ***
由于处理器默认浮点运算
x*y/z
先使用80位进行运算,再截取到64位,strictfp为运算过程中就要严格按照64位进行运算

public static strictfp void main(String[] args)

floorMod方法的作用
reminder运算的负数问题用floorMod解决

数字类型自动转换的原则和方向,数据丢失的情况
优先级
float(float, double)>int(long, int)
4 bytes 向 8 bytes的类型转换不丢失精度,如int -> double, int -> long
ex:
double [operator] other type, return double
float [operator] other type, return float
long [operator] other type, return long
int

精度损失情况描述: 哪些是有损失的转化,哪些是没有损失的,为什么?
同类型之间的,由低精度向高精度转换无精度损失: 如 short->int->long, float->double
int->double无损失,但int->float有损失,因为float位数不足以表示int大范围的精度

如何进行四舍五入,将9.997转为int?
Math.round()返回值为long型,需要类型转换 (int)Math.round(9.997)

位运算及其作用?
用于去某个数值二进制位上的最高位。ex:

System.out.println(10 & 0b1000); //10的二进制是1010,取最高位为1000,转换成10进制是8

你可能感兴趣的:(2017.6.8 运算符)