Methods for Digital Processing of es6 (5)

  • 2021-08-05 08:11:26
  • OfStack


// Math.trunc Method is used to remove 1 The decimal part of the number and returns the integer part. 
 Math.trunc(4.1) // 4
 Math.trunc(4.9) // 4
 Math.trunc(-4.1) // -4
 Math.trunc(-4.9) // -4
 Math.trunc(NaN); // NaN
 Math.trunc('foo'); // NaN
 Math.trunc(); // NaN

// Math.sign Method is used to judge 1 Whether the number is positive, negative or zero. 
 //  It returns 5 Species value. 
 //  Parameter is a positive number, and returns +1 ; 
 //  Parameter is a negative number and returns -1 ; 
 //  Parameter is 0 , return 0 ; 
 //  Parameter is -0 , return -0;
 //  Other values, returning NaN . 
 // 
 Math.sign(-5) // -1
 Math.sign(5) // +1
 Math.sign(0) // +0
 Math.sign(-0) // -0
 Math.sign(NaN) // NaN
 Math.sign('foo'); // NaN
 Math.sign(); // NaN

// Math.cbrt Method is used to calculate 1 Cube root of number 
 Math.cbrt(-1); // -1
 Math.cbrt(0); // 0
 Math.cbrt(1); // 1
 Math.cbrt(2); // 1.2599210498948734

// JavaScript Use the integer of 32 Bit 2 In binary form, Math.clz32 Method returns 1 Numeric 32 How many preambles does the bit unsigned integer form have 0 . 
 Math.clz32(0) // 32
 Math.clz32(1) // 31
 Math.clz32(1000) // 22
//  For decimals, Math.clz32 Method only considers the integer part. 
 Math.clz32(3.2) // 30
 Math.clz32(3.9) // 30
//  For null values or other types of values, Math.clz32 Method converts them to numeric values before calculating them. 
 Math.clz32() // 32
 Math.clz32(NaN) // 32
 Math.clz32(Infinity) // 32
 Math.clz32(null) // 32
 Math.clz32('foo') // 32
 Math.clz32([]) // 32
 Math.clz32({}) // 32
 Math.clz32(true) // 31

// Math.imul Method returns two numbers to 32 The result of multiplication in the form of signed integers, which also returns 1 A 32 Signed integer of bits 
 Math.imul(2, 4); // 8
 Math.imul(-1, 8); // -8
 Math.imul(-2, -2); // 4

Related articles: