Expansion of numeric values

Source: Internet
Author: User
Tags hypot natural logarithm

One or two binary and octal notation

1. ES6 provides a new notation for binary and octal values, respectively, with a prefix 0b (or 0B ) and/ 0o or 0O .

2. Use the method if you want to convert 0b 0o The string value of the prefix to decimal Number .

II, Number.isfinite (), Number.isnan ()

1, used to check Infinite and NaN these two special values.

2, they and the traditional global method isFinite() and isNaN() The difference is that the traditional method first call Number() the value of the non-value into a value, and then to judge, and these two new methods only valid for the value, non-numeric all return

false.

SAN, Number.parseint (), Number.parsefloat ()

1, ES6 the global method parseInt() and parseFloat() , the migration to the number object above, the behavior completely remains unchanged.

Iv. Number.isinteger ()

1,Number.isinteger () is used to determine whether a value is an integer. Note that within JavaScript, integers and floating-point numbers are the same storage method, so 3 and 3.0 are considered the same value.

Wu, Number.epsilon

1, ES6 on the Number object, add a very small constant Number.EPSILON . = = 2.220446049250313e-16

2. The purpose of introducing such a small quantity is to set an error range for floating-point number calculation. We know that floating-point calculations are inaccurate.

Six, safe integers and Number.issafeinteger ()//Number类型统一按浮点数处理,64位存储,整数是按最大54位来算最大最小数的

1, JavaScript can accurately represent the range of integers -2^53 in 2^53 between (excluding two endpoints), beyond this range, can not accurately represent this value.

2, ES6 introduced Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER these two constants, used to indicate the upper and lower bounds of this range.

3,Number.issafeinteger () is used to determine whether an integer falls within this range.

Vii. extension of the Math object

1,Math.trunc ()

Used to remove the fractional part of a number and return the integer portion.

For non-numeric values, the Math.trunc internal use Number method converts the its first to a numeric value.

For null values and values that cannot intercept integers, a nan is returned.

For environments where this method is not deployed, it can be simulated with the following code.

function (x) {  return x < 0?  Math.ceil (x): Math.floor (x);};

2, Math.sign ()

Used to determine whether a number is positive, negative, or zero.

    • The parameter is positive and returns +1;
    • The parameter is negative and returns-1;
    • The parameter is 0 and returns 0;
    • The parameter is-0, returns-0;
    • The other value, which returns Nan.

For environments where this method is not deployed, it can be simulated with the following code.

function (x) {  //  Convert to anumber  if (x = = 0 | | IsNaN (x)) {    return  x;  }   return x > 0? 1:-1;};

3, MATH.CBRT ()

Used to calculate the cube root of a number

For a non-numeric value, the Math.cbrt method is used Number to convert it to a numeric value first.

For environments where this method is not deployed, it can be simulated with the following code.

function (x) {  var y = Math.pow (Math.Abs (x), 1/3);  return x < 0? -y:y;};

4, Math.clz32 ()

The integer of JavaScript is represented by a 32-bit binary form, and the Math.clz32 method returns the number of leading 0 in the form of a 32-bit unsigned integer.

clz32 This function name comes from "count leading zero bits in 32-bit binary

For decimals, the Math.clz32 method considers only the integer part.

For null values or other types of values, the Math.clz32 method converts them first to numeric values before being evaluated.

5, Math.imul ()

The Math.imul method returns the result of two numbers multiplied by a 32-bit signed integer, and returns a 32-bit signed integer.

If only the last 32 bits are considered, most of the time, the Math.imul(a, b) a * b result is the same as the effect that the method equates to (a * b)|0 (a partial overflow of more than 32 bits). The reason you need to deploy this method

Because JavaScript has a precision limit, more than 2 of the 53-square value cannot be accurately represented. This means that for the multiplication of large numbers, low values are often inaccurate, and Math.imul the method can return the correct low value.

6, Math.fround ()

The Math.fround method returns the form of a single-precision floating-point number.

7, Math.hypot ()

The Math.hypot method returns the square root of the sum of squares of all parameters.

8. Logarithmic method

math.expm1 (x) returns ex -1, that is Math.exp(x) - 1 .

The math.log1p (x) method returns 1 + x the natural logarithm, that is Math.log(1 + x) . If x it is less than-1, return NaN .

math.log10 (x) returns the logarithm of base 10 x . If it x is less than 0, Nan is returned.

For environments where this method is not deployed, it can be simulated with the following code.

function (x) {  return Math.log (x)/ math.ln10;};

math.log2 (x) returns the logarithm of base 2 x . If it x is less than 0, Nan is returned.

For environments where this method is not deployed, it can be simulated with the following code.

function (x) {  return Math.log (x)/ MATH.LN2;};

9. Trigonometric Function method

    • Math.sinh (x) returns x the hyperbolic sine (hyperbolic sine)
    • Math.cosh(x)return x hyperbolic cosine (hyperbolic cosine)
    • Math.tanh(x)xthe hyperbolic tangent returned (hyperbolic tangent)
    • Math.asinh(x)Returns x the inverse hyperbolic sine (inverse hyperbolic sine)
    • Math.acosh(x)Returns x the inverse hyperbolic cosine (inverse hyperbolic cosine)
    • Math.atanh(x)xinverse hyperbolic tangent returned (inverse hyperbolic tangent)

Expansion of numeric values

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.