{
//二进制数值都是0b开头,八进制0o
console.log(0b111110111) //503
console.log(0o767); //503
}
{
console.log('15',Number.isFinite(15)); //true
console.log('NaN',Number.isFinite(NaN)); //false NaN 本就不是一个数
console.log('1/0',Number.isFinite('true'/0)); //false
// 判断是不是数
console.log('NaN',Number.isNaN(NaN)); //true
console.log('0',Number.isNaN(0)); //false
}
//判断是不是整数
{
console.log('25',Number.isInteger(25)) //true
console.log('25.0',Number.isInteger(25.0)) //true
console.log('25.1',Number.isInteger(25.1)) //false
console.log('25.1',Number.isInteger('25.1')) //false
}
//判断是不是在-2的53次方,和2的53次方区间,不好含本身
{
console.log(Number.MAX_SAFE_INTEGER); //9007199254740991
console.log(Number.MIN_SAFE_INTEGER); //-9007199254740991
}
//判断是不是安全的
{
console.log('10',Number.isSafeInteger(10)); //true
console.log('a',Number.isSafeInteger('a')); //false
}
//取整
{
console.log(4.1,Math.trunc(4.1)); //4
console.log(4.9,Math.trunc(4.9)); //4
}
//判断一个数整数还是负数还是0
{
console.log('-5',Math.sign(-5)); //-1
console.log('0',Math.sign(0)); //0
console.log('5',Math.sign(5)); //1
console.log('50',Math.sign('50')); //1
console.log('foo',Math.sign('foo')); //NaN
}
//立方根的计算
{
console.log('-1',Math.cbrt(-1));//-1
console.log('8',Math.cbrt(8));//2;
}