In JavaScript, integer values and floating-point values are not distinguished, and all numbers are represented by floating-point values. JavaScript uses the IEEE 754 standard (interested in browsing the IEEE 754 standard under the Network specification classification, need the original file please contact me in the message) the defined 64-bit floating-point format represents the number.
Currently, only floating-point numbers are calculated. Other content will be completed in the following time, but also hope that everyone actively provide resources, so that you learn more.
Floating-point direct quantities can be expressed in the following syntax:
[Digits] [. Digits] [(E|e) [(+|-)]digits]
IEEE754 is a binary notation that can be accurately represented (1/2,1/8, and so on), while commonly used decimal fractions (1/10, 1/100) do not accurately represent
The following tool methods are available for everyone to use.
Previously found some information on the Internet, using the process found that division a bit of a problem, here are two ways to implement:
//Description: This function returns a more accurate addition result. //Floatadd (ARG1,ARG2)//return value: Arg1 plus arg2 's exact resultfunctionFloatadd (arg1,arg2) {varR1=0,r2=0; Try{r1=arg1.tostring (). Split (".") [1].length}Catch(e) {}Try{r2=arg2.tostring (). Split (".") [1].length}Catch(e) {} m=math.pow (10, Math.max (R1,R2))return(arg1*m+arg2*m)/M}//This function returns a more accurate subtraction result. //floatsub (ARG1,ARG2)//return value: Arg1 minus the exact result of Arg2functionfloatsub (arg1,arg2) {returnFloatadd (arg1,-arg2); }//This function returns a more accurate multiplication result. //Floatmul (ARG1,ARG2)//return value: arg1 times the exact result of Arg2functionFloatmul (arg1,arg2) {varM=0,s1=arg1.tostring (), s2=arg2.tostring (); Try{M+=s1.split (".") [1].length}Catch(e) {}Try{M+=s2.split (".") [1].length}Catch(e) {}returnNumber (S1.replace (".", "")) *number (S2.replace (".", ""))/math.pow (10,m)}//This function returns a more accurate division result. //Call: Floatdiv (ARG1,ARG2)//return value: Arg1 divided by the exact result of Arg2functionFloatdiv (arg1,arg2) {varT1=0,t2=0, R1,R2; Try{t1=arg1.tostring (). Split (".") [1].length}Catch(e) {}Try{t2=arg2.tostring (). Split (".") [1].length}Catch(e) {} r1=number (Arg1.tostring (). Replace (".", "")) R2=number (Arg2.tostring (). Replace (".", "")) returnFloatmul (R1/R2), Math.pow (10,T2-T1)); Call multiplication}functionFloatDiv2 (arg1,arg2) {varM=0,s1=arg1.tostring (), s2=arg2.tostring (), R1,SR1; Try{M+=s1.split (".") [1].length}Catch(e) {}Try{M+=s2.split (".") [1].length}Catch(e) {} r1=number (S1.replace (".", ""))/number (S2.replace (".", ""))Try{m+=r1.tostring (). Split (".") [1].length}Catch(e) {}returnNumber (r1.tostring (). Replace (".", ""))/math.pow (10,m)}
JavaScript Deep learning and common tool methods----01. Floating-point number