Mozilla¿ª·¢ÕßÉçÇøÊÇÎÒѧϰµÄÖØҪ;¾¶£¬ÓÐÒ»´Î¹äµ½Õâ¸öAPI¿´µ½PolyfillÓм¸ÐдúÂ룺
var list = Object(this); var length = list.length >>> 0;
ÓÉÓÚ·ÇCSµÄijҰÉúרҵ³öÉí£¬ÎÒ¶ÔλÔËËã·ûµÄÁ˽â±È½ÏÄ£ºý£¬´ó¸ÅÄÜÃ÷°×µÄÖ»ÊÇlist.length >>> 0¶Ôlist.length×öÎÞ·ûºÅÓÒÒÆ£¬¶ø·µ»ØÖµÊÇ>=0µÄÕûÊý£¬µ«±³ºóµÄÔËËã¹ý³Ì£¬¾Í²»ÄÜ˵µÃÇå³þÁË¡£¸´Ï°ÁËÒ»ÏÂÏà¹Ø֪ʶ£¬×ö¸ö±Ê¼Ç¡£
½ñÌìÌÖÂÛʲô£¿
±¾ÎÄ£¬½«³¢ÊÔ´ÓÏÖ´ú¼ÆËã»úÖжÔÊý×ֵĴ洢ºÍ¼ÆËãÌÖÂÛÆð£¬ÕâÒ²×¢¶¨£¬ËäÈ»ÌâÄ¿½Ð”Numbers in JavaScript”£¬µ«ÊÇ´óÁ¿Æª·ùÓ¦¸Ã¼¯ÖÐÔÚ±à³ÌÓïÑÔÖÐÖ÷ҪʹÓõÄÊý×Ö´¦ÀíµÄ·½Ê½¡£Íò±ä²»ÀëÆä×Ú£¬¶®ÁËÔÀíÖ®ºó£¬¶ÔÕÆÎÕ¸÷ÖÖÓïÑÔΧÈÆͬÑùÔÀí¹¹½¨µÄNumberÒ²¾ÍÇáËɶàÁË¡£µ±È»£¬ÕâÆäÖоͰüÀ¨JavaScript¡£
ÏÈÏ뼸¸öÎÊÌâ°É£º
- JavaScriptµÄÊý×ÖΪʲôÓÐ0ºÍ-0£¿
- JavaScriptÖеÄNaNΪʲô»¥²»ÏàµÈ£¿
- JavaScriptÖеÄÊý×ÖÕæµÄÖ»ÓÐÒ»ÖÖÀàÐÍÂð£¿
- JavaScriptÖг£±»Ú¸²¡µÄ0.3 - 0.2 == 0.1ÔÒòÊÇʲô£¿
- Êý×éµÄ×î´ó³¤¶ÈÊǶàÉÙ£¿ÎªÊ²Ã´ÊÇÕâ¸öÖµ£¿
- ÉÏÊöÎÊÌ⣬ֻÓÐÔÚJavaScriptÖÐÓÐÂð£¿
µ±Ï£¬¼ÆËã»úÈç´ËÆÕ¼°£¬ÎÒÏàÐÅ£¬¼´±ã·Ç³ÌÐòÔ±Ò²Á˽⣺¼ÆËã»úµÄÊÀ½çÖ»ÓÐ0ºÍ1¡£¶øÒ»¸ö³ÌÐòÔ±Ó¦¸ÃÁ˽⣺0/1×é³ÉµÄ¶«Î÷½Ð»úÆ÷Â룬ÓÐÔÂë, ·´Âë, ²¹ÂëµÈ¡£¶øÒ»¸öJS³ÌÐòÔ±Ó¦¸ÃÁ˽⣺JSÖеÄÊý×ÖÊDz»·ÖÀàÐ͵ģ¬Ò²¾ÍÊÇûÓÐbyte/int/float/doubleµÈµÄ²îÒì¡£¶øÒ»¸öÉÔ΢Ñо¿ES¹æ·¶µÄJS³ÌÐòÔ±Ó¦¸ÃÁ˽⣺JSµÄnumberÊÇIEEE 754±ê×¼ÏÂ64-bitsµÄË«¾«¶ÈÊýÖµ£¬¶øÇÒESÖÐÓÐToInteger/ToInt32/ToUint32/ToUint16µÈType Conversion¡£ÏÂÃ棬ÎÒÃǾͳ¢ÊÔ×ÅÌÖÂÛÒ»ÏÂÕâЩ¡£
´ÓÓ²¼þµÄ½Ç¶ÈÉϽ²£¬Î¬»¤Á½¸ö״̬ÊÇÏà¶ÔÈÝÒ׵ģ¬±ÈÈçÒ»¸ö¶þ¼«¹ÜµÄµ¼Í¨»òÕß½ØÖ¹£¬Ò»¸öµçÂö³åµÄ¸ß»òÕߵͣ¬´Ó¶øÔÚʵÏÖ¼¯³Éµç·ʱºò¿ÉÒÔ¸ü¼Ó¼òµ¥¸ßЧ£¬ËùÒÔ¼ÆËã»úÆÕ±éʹÓÃ0ºÍ1À´´æ´¢ºÍ¼ÆËã¡£ÄÇô£¬Ö»ÓÐ0ºÍ1£¬ÈçºÎ±íʾ1234567890ÄØ£¿Õâ¾ÍÉæ¼°µ½»úÆ÷ÂëºÍÕæÖµ¡£
»úÆ÷ÂëºÍÕæÖµ
Ëùν»úÆ÷ÂëÊÇÖ¸£¬ÕûÊýÔÚ¼ÆËã»úÖжþ½øÖÆÐÎʽ¡£¹æÔòºÜ¼òµ¥£¬»úÆ÷ÂëµÄ×î¸ß루×óµÚһ룩±íʾÊý×ÖµÄÕý¸º£¬0±íʾÕýÊý£¬1±íʾ¸ºÊý£¬ÆäÓàλ°´ÕÕ½øÖÆת»»µÄ¹æÔò±íʾ¾ßÌåÊý×Ö¡£
ËùνÕæÖµÊÇÖ¸£¬»úÆ÷Âë°´ÕÕÉÏÊöת»»¹æÔò»¹ÔµÄ´øÓÐÕý¸ºµÄʵ¼ÊÕûÊý¡£
¾ÙÀý¶øÑÔ£¬ÓÃ8-bits±íʾһ¸öÕûÊý£¬ÔòÊ®½øÖƵÄÕûÊý+6¿É±íʾΪ£º00000110£»Ê®½øÖƵÄÊý×Ö-5¿É±íʾΪ10000101¡£ÕâÀï˵µÄ+6ºÍ-5±ãÊÇÕæÖµ£¬¶ø±íʾËüÃǵĶþ½øÖÆÊý±ãÊÇ»úÆ÷Âë¡£ÔÙ´Î×¢Ò⣬×î¸ßλֻÓÃÓÚ±íʾÕý¸º£¬±ÈÈç10000101µÄÕæÖµÊÇ-5¶ø·Ç133£¬ÒÔ¼°ÎÒÃǹØÓÚ»úÆ÷ÂëºÍÕæÖµµÄÌÖÂÛÊÇ»ùÓÚÕûÊý·¶Î§µÄ£¬¸¡µãÊýÔÚ¼ÆËã»úÖеĴ洢·½Ê½ÓëÕûÊýÓкܴó²îÖµ£¬½«Áí×÷ÌÖÂÛ¡£
ÓÐÁË»úÆ÷Â룬ÎÒÃDZã¿ÉÒÔÔÚ¼ÆËã»úÖÐʹÓûúÆ÷Âë´æ´¢ºÍ¼ÆËãÕæÖµ£¬ÄÇô»úÆ÷ÂëÔÚ¼ÆËã»úÖÐÊÇÈçºÎ¼ÆËãµÄÄØ£¿
ÔÂë¡¢·´Âë¡¢²¹Âë
»úÆ÷Âë·ÖΪ¶àÖÖ£¬Ö÷Òª°üÀ¨ÔÂë¡¢·´Âë¡¢²¹Âë¡¢ÒÆÂëµÈ£¬½ñÌìÎÒÃÇÖ÷Òª×ܽáÒ»ÏÂÇ°Èý¸ö£¬¶øÒÆÂë·Ç³£¼òµ¥£¬ÇÒ¶àÓÃÓڱȽϣ¬²»×öÏêϸ˵Ã÷¡£ÁíÍâÐèÒª²¹³äÒ»µã£¬ÎÒÃÇÔÚ´ËÇø·Ö»úÆ÷ÂëµÄÕâô¶àÖÖÐÎʽ£¬Ö÷ÒªÊÇÕë¶ÔµÄÓзûºÅÊý£¬¶øÎÞ·ûºÅÊý£¬²»ÐèҪʹÓÃ×î¸ßλÀ´±íʾÕý¸º£¬Ò²¾Í²»ÐèÒªÕâô¶àÖÖ±àÂ뷽ʽ¡£
ÔÂ룺
×î¸ßλ±íʾÕý¸º£¬ÆäËüλ±íʾÕæÖµµÄ¾ø¶ÔÖµ¡£ÆäÖУ¬×î¸ßλΪ0±íʾÕýÊý»òÕß0£¬Îª1±íʾ¸ºÊý¡£
±ÈÈ磬ͬÑùÒÔ8bits³¤¶ÈµÄÊý´®±íʾ+7µÄÔÂëΪ0000 0111£¬-7µÄÔÂëΪ10000111¡£ÒÔºó£¬ÎÒÃÇ»áÕâÑù±íʾ£º
[+7] = [00000111]Ô [-7] = [10000111]Ô
ºÜÃ÷ÏÔ£¬8-bitsµÄÔÂëÄܼǼµÄ·¶Î§Îª£º[-127,+127].
ÔÂëµÄºÃ´¦ÔÚÓÚ£¬Ò×ÓÚÀí½â£¬Ïà¶ÔÖ±¹Û£¬·½±ãÈËÄÔʶ±ðºÍ¼ÆËã¡£
¶ÔÓÚÔÂ룬ÈËÄÔʹÓ㬿ÉÒÔÖ±½Ó¼ÆËã³öÆäÕæֵȻºó¿ÉÒÔ½øÐкóÐø²Ù×÷¡£µ«¶ÔÓÚ¼ÆËã»ú£¬Ê×ÏÈ£¬ÒòΪ×î¸ßλÓÃÓÚ±íʾÕý¸º£¬ËùÒÔ²»ÄÜÖ±½Ó²ÎÓëÔËË㣬ÐèҪʶ±ðÈ»ºó×öÌØÊâ´¦Àí£»Æä´Î£¬¾ßÌå¼ÆËãʹÓþø¶ÔÖµ½øÐвÙ×÷£¬ËùÒÔÁ½¸ö²Ù×÷ÊýÕý¸ºµÄÒìͬ»áÓ°Ïì²Ù×÷·û£¬±ÈÈçÁ½¸öÒìºÅÏà¼Óʵ¼ÊÒª×ö¼õ·¨²Ù×÷£¬ÉõÖÁÒìºÅÏà¼õ»¹ÐèÒªÅжϾø¶ÔÖµ´óСȻºó¾ö¶¨½á¹ûÕý¸º¡£Èç´Ë£¬ÎÒÃǼÆËã»úµÄÔËËãÆ÷Éè¼Æ½«»á±äµÃÒì³£¸´ÔÓ¡£ÏÂÃ棬ÎÒÃǽ«Á˽âÈçºÎʹÓ÷´ÂëºÍ²¹Â뽫·ûºÅλ²ÎÓëÔËË㣬´Ó¶øʹ¼Ó¼õ·¨Í³Ò»¼òµ¥¸ßЧµØ´¦Àí£¬ÕâÒ²ÊÇ·´ÂëºÍ²¹Âë³öÏÖµÄÔÒò¡£
·´Â룺
ÕýÊýµÄ·´ÂëµÈÓÚÆäÔÂ룬¶ø¸ºÊýµÄ·´ÂëÔòÊǶÔÆäÔÂë½øÐзûºÅλ²»±ä£¬ÆäËüλÖðһȡ·´µÄ½á¹û¡£
±ÈÈ磬ͬÑùÒÔ8-bits³¤¶ÈµÄÊý´®±íʾ+7£¬ÄÇôÓÐÈçÏ£º
[+7] = [00000111]Ô = [00000111]·´ [-7] = [10000111]Ô = [11111000]·´
ͬÑù£¬8-bitsµÄ·´ÂëÄܼǼµÄ·¶Î§Îª£º[-127,+127]¡£
ÔÚ°´Î»È¡·´Ö®ºó£¬ÎÒÃÇ¿ÉÒÔÓÐÏÂÃæµÄ²Ù×÷£º
2 - 3 = 2 + (-3) = [00000010]Ô + [10000011]Ô = [00000010]·´ + [11111100]·´ = [11111110]·´ = [10000001]Ô = -1
ÉÏÃ棬ÎÒÃǽ«¼õ·¨Í¨¹ý·´Âëת»¯ÎªÁ˼ӷ¨£¬Èç´Ë£¬ÎÒÃǵÄÔËË㽫»á¼òµ¥ºÜ¶à£¬µ«ÊÇ·´ÂëµÄ·½Ê½Í¬Ñù´æÔÚһЩÎÊÌ⣺
3 - 3 = 3 + (-3) = [00000011]Ô + [10000011]Ô = [00000011]·´ + [11111100]·´ = [11111111]·´ = [10000000]Ô = -0
³öÏÖÁË-0£¬Õâ¸öÖµÊÇûÓÐÒâÒåµÄ¡£ÁíÍ⣬°´ÕÕ·´Âë¼Ó·¨·¨Ôò£¬Èç¹û×î¸ßλÓнø룬ÐèÒªÔÚ×îµÍλÉÏ+1£¬ÄÇô»á³öÏÖ£º
3 - 2 = 3 + (-2) = [00000011]Ô + [10000010]Ô = [00000011]·´ + [11111101]·´ (ÕâÀï×î¸ßλÓнø룬ÐèÒªÔÚ×îµÍλ+1) = [00000001]·´ = [00000001]Ô = 1
ÕâÖÖÇé¿ö£¬ÓÖÔö¼ÓÁË·´ÂëÔËËãµÄ¸´ÔÓÐÔ£¬Ó°ÏìЧÂÊ£¬Îª½â¾öÉÏÃæµÄÎÊÌ⣬³öÏÖÁ˲¹Âë¡£
²¹Â룺
ÕýÊýµÄ·´ÂëµÈÓÚÆäÔÂ룬¶ø¸ºÊýµÄ²¹ÂëÔòÊǶÔÆä·´Âë½øÐÐĩλ¼Ó1µÄ½á¹û¡£
±ÈÈ磬ÔÙͬÑùÒÔ8-bits³¤¶ÈµÄÊý´®±íʾ+7£¬ÄÇôÓÐÈçÏ£º
[+7] = [00000111]Ô = [00000111]·´ = [00000111]²¹ [-7] = [10000111]Ô = [11111000]·´ = [11111001]²¹
ʹÓò¹Â룬¼ÌÐø×ö֮ǰµÄ²Ù×÷£º
2 - 3 = 2 + (-3) = [00000010]Ô + [10000011]Ô = [00000010]·´ + [11111100]·´ = [00000010]²¹ + [11111101]²¹ = [11111111]²¹ = [11111110]·´ = [10000001]Ô = -1
ÄÇô£¬Èç¹ûÊÇ3-3ÄØ£¿
3 - 3 = 3 + (-3) = [00000011]Ô + [10000011]Ô = [00000011]·´ + [11111100]·´ = [00000011]²¹ + [11111101]²¹ = [00000000]²¹ = [00000000]Ô = 0
ÊÇ·ñ»¹ÐèÒª×ö¶îÍâµÄ¼Ó·¨²Ù×÷£¿
3 - 2 = 3 + (-2) = [00000011]Ô + [10000010]Ô = [00000011]·´ + [11111101]·´ = [00000011]²¹ + [11111110]²¹ = [00000001]²¹ = [00000001]Ô = 1
ÕâÑù£¬ÎÒÃDZã¿ÉÒÔÍêÃÀµÄ½«¼õ·¨Í³Ò»µ½¼Ó·¨Ö®ÉÏ£¬¶øÇÒ²»ÐèÒª·±ËöµÄÕý¸ºÅжϣ¬½øλ¿ØÖÆ£¬ÉõÖÁ¿ÉÒÔ½ÚÔ¼Ò»¸öλÖá£ÄÇô£¬Õâ¸öλÖã¬Ò²¾ÍÊÇ10000000ÈçºÎ´¦ÀíÄØ£¿°´Õչ涨£¬10000000ÓÃÀ´±íʾ-128£¬ÕýÊýµÄ²¹Âë/·´Âë/ÔÂëÏàͬ£¬¶ø¸ºÊýµÄ²¹ÂëÖ»ÊÇÕ¼ÓÃÁË-0µÄ[10000000]ÔºÍ[11111111]·´×ª»»ºóµÃµ½µÄ[10000000]²¹±íʾ-128£¬µ«ÊÇÕâ¸öÖ»ÊÇ°ïÖúÀí½â£¬²»ÄÜ·´Ïò»ØÍƵõ½-128µÄÔÂëºÍ²¹Âë¡£
ËùÒÔ£¬8bitsµÄ²¹ÂëÄܼǼµÄ·¶Î§Îª£º[-128,+127]¡£
ÖÁ´Ë£¬ÎÒÃÇÒѾÁ˽âÁË£¬¼ÆËã»úÖÐÖ÷ҪʹÓõĴ洢ºÍ¼ÆËãÕûÊýµÄ·½Ê½£¬¼øÓÚÏÖ´ú¼ÆËã»úÖ÷ҪʹÓò¹Â뷽ʽ£¬×ÔÈ»ÄܺÜÈÝÒ×Àí½â¸÷ÖÖÊý×ÖÀàÐ͵ıíʾ·¶Î§£¬±ÈÈç32bitsµÄint·¶Î§Îª£º[-231,231-1]¡£Õâ¶ÔÓÚÎÒÃǺóÃæÀí½âһЩJavaScriptÖеļ«¶ËÇé¿öÖÁ¹ØÖØÒª¡£
ÉÔ¼Ó²¹³ä£º
ÎÒÃÇ¿ÉÄÜ»áÏ룬ÔÂëºÜÈÝÒ×½ÓÊܵģ¬¿ÉÊÇ·´ÂëºÍ²¹ÂëµÄ³öÏÖÊÇ»ùÓÚʲôÑùµÄÂß¼»òÕßÊýѧÔÀíÄØ£¿ÕâÀÎÒÃÇ¿ÉÒÔòßòѵãË®µØÌÖÂÛһϣ¬ÒòΪÕâ¸ötreadÒѾ³¬³ö½ñÌì»°ÌâÓеã¶àÁË¡£
³£ÓÃÀ´ËµÃ÷Õâ¸öÔÀíµÄÀý×ÓÊÇʱÖÓ£¬Ê±ÖÓµÄÒ»ÖÜÓÐ12¸öÊý×Ö£¬ÄÇô£¬Èç¹ûÎÒÃÇÏ£Íû´Ó3µ÷Õûµ½8¸ÃÈçºÎ²Ù×÷£¿¿ÉÒÔÍùÇ°+5£¬Ò²¿ÉÒÔÍùºó-7¡£ÕâÀïµÄÁ½¸öÊý×Ö£¬+5ºÍ-7´æÔÚ×ŵĹØϵ£ºËüÃÇͬʱ¶ÔÊý×Ö12ÇóÓàÊýµÃµ½Í¬ÑùµÄ½á¹û¡£ÑϸñµÄ¸ÅÄîÊÇÎÒÃÇСʱºòѧϰµÄͬÓ࣬׼ȷµÄÃèÊöÉÏÃæµÄ¹ØϵÊÇ+5ºÍ-7¶ÔÄ£12ͬÓ࣬+5ºÍ-7ÊÇ»¥²¹¹Øϵ£¬»¥Îª²¹Âë¡£ÎÒÃÇ¿ÉÒÔ¿´³ö£¬ÔÚÄ£µÄÊý×Ö·¶Î§Ö®ÄÚ£¬ÎÒÃǼõÈ¥Ò»¸öÊý×Ö£¬Ç¡ºÃµÈÓÚ¼ÓÉÏÕâ¸öÊý×ֵIJ¹ÂëÈ»ºóÈ¡Óà¡£´óÖ¾ÍÕâôÃèÊöһϣ¬ÏêϸµÄ¹ý³ÌÊÇÐèÒªÑϽ÷µÄ¿Æѧ֤Ã÷£¬ÍøÉÏÓдóÁ¿µÄÎÄÏ×£¬ÔÚ´ËÎÒÃÇÊÊʱÊÕסµãµ½ÎªÖ¹£¬ÓÐÐËȤµÄͬѧ×ÔÐÐgoogle°É¡£
IEEE 754±ê×¼
×÷Ϊһ¸öJavaScript³ÌÐòÔ±£¬ÎÒÃÇÖ»ÓÐÒ»¸öNumber£¬ËùÒÔÎÒÃÇ´ÓÒ»¿ªÊ¼¾ÍÏ°¹ßÁË£º
var num1 = 123; var num2 = 1.23;
µ«ÊÇ£¬ÄãÖªµÀJSµÄnumberÊÇIEEE 754±ê×¼µÄ64-bitsµÄË«¾«¶ÈÊýÖµÂð£¿ÕâÊÇÒ»¸öʲôÑùµÄ±ê×¼£¿Ê¹ÓÃÕâ¸ö±ê×¼µÄ64-bitsË«¾«¶ÈÒâζ×Åʲô£¿ËùÒÔ£¬ÒªÕÆÎÕJavaScriptÖеÄÊý×Ö£¬ÎÒÃÇÊ×ÏȵÃÁ˽âIEEE 754±ê×¼¡£ÏÂÃ棬ÎÒ½«³¢ÊÔ˵Ã÷Ò»ÏÂÕâ¸ö±ê×¼£¬ÎªÎÒÃÇ×îºóѧϰJavaScriptÖеÄÊý×Ö×öÆ̵档
±ê×¼µÄ»ù±¾ÔÀí£º
ÎÒÃÇÖªµÀ£¬¶ÔÓÚ¼ÆËã»ú¶øÑÔ£¬Êý×ÖûÓÐСÊýºÍÕûÊýµÄ²î±ð£¬Ò²¾ÍÊǼÆËã»úÖÐûÓÐСÊýµãµÄ´æÔÚ¡£Í¨¹ýÇ°ÎĵÄÌÖÂÛ£¬ÎÒÃÇÒѾÕÒµ½Á˺ÜÍêÃÀµÄÕûÊý´æ´¢¼ÆËãµÄ·½°¸£¬µ«Êǵ±Éæ¼°µ½Ð¡Êý£¬ÎÒÃǺÜÈÝÒ×·¢ÏÖ£¬ÏÖÓеķ½°¸ÎÞ·¨½â¾öÎÒÃǵÄÐèÇó¡£È»ºó£¬¼ÆËã»ú¿Æѧ¼ÒÃDZ㳢ÊÔÁ˶àÖÖ·½°¸£¬Ö÷Òª±ãÊǶ¨µãÊýºÍ¸¡µãÊýÁ½ÖÖ¡£
Ëùν¶¨µãÊý£¬ÊÇָСÊýµãλÖù̶¨ÔÚÊý´®ÖмäµÄij¸öÌض¨Î»Ö㬵ãÁ½²à·Ö±ðΪÊý×ÖµÄÕûÊýºÍСÊý²¿·Ö¡£±ÈÈçÓÃ8-bits×Ö³¤µÄÊý´®£¬Ð¡Êýµã¹Ì¶¨ÔÚÕýÖмäλÖã¬ÄÇô11001001ºÍ00110101·Ö±ð±íʾ1100.1001ºÍ11.0101Á½¸öÊý×Ö¡£ÕâÖÖ·½°¸¼òµ¥Ö±¹ÛÒ×Àí½â£¬µ«ÊÇ´æÔÚÑÏÖصĿռäÀË·Ñ£¬ÒÔ¼°ÈÝÒ×Òç³öµÄÎÊÌâ¡£
Ëùν¸¡µãÊý£¬ÊÇָСÊýµãµÄλÖÃÊDz»¹Ì¶¨µÄ£¬Í¨¹ý¿Æѧ¼ÆÊý·¨(Õâ¸öÓ¦¸Ã²»ÐèÒª½âÊÍ°É)µÄ·½Ê½¿ØÖÆСÊýµãµÄλÖ㬱íʾ²»Í¬µÄÊý×Ö¡£Õâ¸ö±íʾ·½°¸±ãÊÇIEEE 754±ê׼ʹÓõķ½°¸¡£IEEE 754±ê×¼ÊÇĿǰʹÓÃ×î¹ã·ºµÄ¸¡µãÊýÔËËã±ê×¼¡£ÏÂÃæÎÒÃǽ«Ö÷ÒªÌÖÂÛһϴ˷½°¸¡£
ÏÖÔÚ£¬ÈÃÎÒÃÇÏëÒ»ÏÂСʱºòѧϰµÄ¿Æѧ¼ÆÊý·¨£¬±ÈÈç-123.456Õâ¸öÊý×Ö£¬×ª»»³É¿Æѧ¼ÆÊý·¨Ó¦¸ÃÊÇ£º-1.23456 × 10^2¡£ÕâÀïÃæÒѾ°üº¬ÁËIEEE 754±ê×¼µÄÖ÷ÒªÔªËØ¡£ÎÒÃÇÊáÀíһϣºµÚÒ»¸ö£¬×ÔÈ»ÊÇÕý¸ººÅµÄÎÊÌ⣬ÐèÒªÒ»¸ö±êÖ¾£»È»ºó£¬ÐèÒªÒ»¸ö¾ßÌåµÄÊý×Ö£¬±íʾÓÐЧÊý×Ö»òÕß¾«¶È£¬ÈçÉÏÀýµÄ1.23456£»ÔÙÈ»ºó£¬ÐèÒªÒ»¸ö¿ØÖÆСÊýµãλÖõÄÊý×Ö£¬ÈçÉÏÀýµÄ10^2£¬»ØÒäһϣ¬ÎÒÃÇѧϰ¿Æѧ¼ÆÊý·¨µÄʱºò£¬ÒªÇóÇ°ÃæµÄÊý×ֵľø¶ÔÖµ´óÓÚ1¶øСÓÚ10£¬Ò²¾ÍÊÇСÓÚ10^2Öеĵ×Êý(Base)£¬½øÖƹ̶¨Ö®ºó£¬µ×ÊýÓ¦¸ÃÊǹ̶¨µÄ£¬ËùÒÔÕâÀïÆð¾ö¶¨×÷ÓõÄÊÇÖ¸Êý£¬Ò²¾ÍÊÇÉÏÀýÖеÄ2¡£ÄÇô£¬ÓÐÁËÕâÈý¸öÔªËØ£¬ÎÒÃDZã¿ÉÒÔºÜÇáËɵıíʾ³öÒ»¸öÊý×Ö£¬²¢ÇÒÁé»îµÄµ÷½ÚСÊýµãλÖôӶø¿ØÖÆÊý×ÖÕý¸º¡¢¾«¶ÈºÍ´óС¡£
ÉÏÃæµÄÒªËØ£¬×ª»»³É±ê×¼ÓïÑÔÃèÊö£¬ÎÒÃdzƱíʾÕý¸ºµÄ±êÖ¾½Ð·ûºÅ(Sign)£¬±íʾ¾«¶ÈµÄÊý×ÖΪβÊý(Mantissa)»òÕßÓÐЧÊý×Ö(Significand)£¬¶ø¿ØÖÆСÊýµãλÖõÄÖ¸Êý¾Í½ÐÖ¸Êý(Exponent)£¬Ö¸ÊýºÍ»ùÊý(Base)¹²Í¬×÷ÓòÎÓë¼ÆËã¡£ÏÂͼȡ×Ôwikipedia£¬ÎÒÃÇÖ±¹ÛµØ¸ÐÊÜÏÂÕâÈý¸öÒªËØÔÚÒ»¸öÊý´®ÖеÄÏà¶Ô¹Øϵ£¨fractionÇøÓò¼´µÈͬÓÚÇ°Ãæ˵µÄÓÐЧÊý×ÖÇøÓò£©£º
Á˽â×î»ù±¾µÄÔÀíºó£¬ÎÒÃÇÀ´´óÖ¿´Ò»ÏÂIEEE 754±ê×¼×öÁËʲô¡£
Ê×ÏÈ×öµÄÊÂÇé¾ÍÊǹ涨ÕâÈý¸öÒªËØÔÚÒ»¸öÊý´®ÖÐÕ¼ÓеÄλÊý£¬ÊÔÏëһϣ¬Èç¹û¸÷¸öʵÏÖµÄλÊý²»È·¶¨£¬ÄÇôÎÒÃÇÊDz»ÊǺÜÄÑÕýÈ·µÄ»¹Ô³öÔʼÊý×Ö£¿IEEE 754±ê×¼¹æ¶¨ÁËËÄÖÖ±íʾ¸¡µãÊýÖµµÄ·½Ê½£ºµ¥¾«È·¶È£¨32룩¡¢Ë«¾«È·¶È£¨64룩¡¢ÑÓÉìµ¥¾«È·¶È£¨43±ÈÌØÒÔÉÏ£¬ºÜÉÙʹÓã©ÓëÑÓÉìË«¾«È·¶È£¨79±ÈÌØÒÔÉÏ£¬Í¨³£ÒÔ80±ÈÌØʵ×ö£©¡£Ö»ÓÐ32λģʽÓÐÇ¿ÖÆÒªÇó£¬ÆäËû¶¼ÊÇÑ¡ÔñÐԵġ£¶øÏÖÔÚÖ÷Á÷µÄÓïÑÔ£¬¶àÌṩÁ˵¥¾«¶ÈºÍË«¾«¶ÈµÄʵÏÖ£¬ÎÒÃÇÔÚ´ËÖ÷Òª±È½ÏÒ»ÏÂÕâÁ½Õߣ¬ÈçͼÊÇËüÃǸ÷¸ö²¿·Ö¶ÔÓ¦ÉÏͼ£¬ËùʹÓõÄλÊýÈçÏ£º
²¹³äÒ»µãµÄÊÇ£¬ÎÞÂÛÊÇ¿Æѧ¼ÆÊý·¨»¹ÊDZê×¼µÄ¹æ¶¨£¬¶¼ÒªÇóÓÐЧÊý×Ö£¨²»¿¼ÂÇ·ûºÅ룩±ØÐë>=1 && <Base¡£ËùÒÔ£¬ÓÐЧÊý×ÖÆäʵÊÇÒ»¸ö¶¨µãÊý£¬Ð¡ÊýµãµÄλÖù̶¨ÔÚÓÐЧÊý×ÖÓòµÄ×î¸ßλºÍ´Î¸ßλ֮¼ä¡£ÄÇô£¬°´ÕÕÉÏÊö¹æ¶¨£¬ÔÚ¶þ½øÖÆÖУ¬×î¸ßλֻÄÜÊÇ1£¬ËùÒÔ±ê×¼ÒªÇóÊ¡ÂÔÆä×î¸ß룬ÓÚÊǾ«¶ÈÌá¸ßһλ¡£±ÈÈ磬32-bitsµÄµ¥¾«¶ÈÓÐЧÊý×ÖÇøÓòÖ»ÓÐ23룬µ«ÊǾ«¶ÈÈ´ÊÇ24λ£»64-bitsµÄË«¾«¶È£¬ÓµÓÐ52λµÄÓÐЧÊý×ÖÓòÈ´ÊÇ54λ¾«¶ÈµÄ¡£
È»ºó£¬»¹ÓÐÒ»¸öÎÊÌ⣬Èç¹û°´ÕÕÏÈÓеÄÔ¼¶¨£¬ÊDz»ÊÇÎÞ·¨±íʾСÓÚ1µÄʵÊý£¿ÒòΪ£¬Ö¸ÊýÒ»¶¨>=0£¬ÓÐЧÊý×ÖÒ»¶¨>1¡£ÓÚÊÇ£¬IEEE 754±ê×¼Ìá³öÁËÒ»¸öºÜÖØÒªµÄÖ¸ÊýÆ«ÒÆÖµ¡£ËüÊÇ˵Ã÷Ö¸ÊýÓò(ExponentÕ¼ÓõÄÇøÓò)µÄ±àÂëֵΪָÊýµÄʵ¼ÊÖµ¼ÓÉÏij¸ö¹Ì¶¨µÄÖµ£¬»»ÑÔÖ®±ãÊÇ£¬Èç¹ûÎÒÃǸù¾ÝÖ¸ÊýÓò¼ÆËã³öµÄÖ¸ÊýÊÇN£¬ÄÇô²ÎÓë¼ÆËãʵ¼Ê¸¡µãÊýµÄÖ¸ÊýÓ¦¸ÃÊÇN-Ö¸ÊýÆ«ÒÆÖµ¡£¸ù¾ÝIEEE 754±ê×¼µÄ¹æ¶¨£¬¸Ã¹Ì¶¨ÖµÎª2^(e-1) - 1£¬ÆäÖеÄeΪ´æ´¢Ö¸ÊýµÄ±ÈÌصij¤¶È¡£±ÈÈ磬´ÓÉÏͼÖÐÎÒÃÇ¿´µ½£¬32-bitsµÄµ¥¾«¶ÈÊÇÒÔ8-bits±íʾһ¸öÖ¸ÊýÓò£¬ÄÇôƫÒÆÖµÓ¦¸ÃÊÇ2^(8-1) - 1 = 128−1 = 127¡£ËùÒÔ£¬ÈÝÒ׵óö£¬µ¥¾«¶È¸¡µãÊýµÄÖ¸Êý²¿·Öʵ¼ÊÈ¡ÖµÊÇ[-127,128]¡£±ÈÈ磬ij¸ö32-bitsµ¥¾«¶ÈµÄÖ¸ÊýΪʮ½øÖƵÄ1£¬ÄÇôָÊýÓòµÄ±àÂëÓ¦¸ÃÊÇ10000001£¬Ä³¸ö32-bitsµ¥¾«¶ÈµÄÖ¸ÊýÓò±àÂëÊÇ00000001£¬ÄÇô¸ÃÖ¸ÊýµÄʵ¼ÊÖµÓ¦¸ÃÊÇÊ®½øÖƵÄ-126¡£ÕâÑù£¬ÎÒÃǾÍÄÜͨ¹ýÆ«ÒÆÖµ½«ÕýÖ¸Êýת»»Îª¸ºÖ¸Êý£¬´Ó¶øʹ¸¡µãÊýÄܱƽü0¡£¸¡µãÊýµÄÖ¸Êý¼ÆËã¸úÇ°ÃæÌÖÂ۵ĻúÆ÷ÂëÇ¡ºÃÏà·´£¬ÕýÊýµÄ×î¸ßλ¶¼ÊÇ1£¬¶ø¸ºÊýµÄ×î¸ßλ¶¼ÊÇ0¡£
ÒÔÉϵÄÃèÊö£¬±ãÊÇIEEE 754±ê×¼×îÐèÒªÎÒÃÇÁ˽âµÄÔÀí²¿·Ö£¬µ«ÊÇ£¬×÷Ϊһ¸ö¹ã·ºÊ¹ÓõĹ¤Òµ±ê×¼£¬¹æ¶¨ÕâЩ»¹ÊÇÔ¶Ô¶²»¹»µÄ¡£
ÉÔ¼Ó²¹³ä£º
wikipedia¶ÔIEEE 754±ê×¼ÓÐÈçÏÂÃèÊö£º
Õâ¸ö±ê×¼¶¨ÒåÁ˱íʾ¸¡µãÊýµÄ¸ñʽ£¨°üÀ¨¸ºÁã-0£©Óë·´³£Öµ£¨denormal number£©£©£¬Ò»Ð©ÌØÊâÊýÖµ£¨ÎÞÇInf£©Óë·ÇÊýÖµ£¨NaN£©£©£¬ÒÔ¼°ÕâЩÊýÖµµÄ“¸¡µãÊýÔËËã·û”£»ËüÒ²Ö¸Ã÷ÁËËÄÖÖÊýÖµÉáÈë¹æÔòºÍÎåÖÖÀýÍâ×´¿ö£¨°üÀ¨ÀýÍâ·¢ÉúµÄʱ»úÓë´¦Àí·½Ê½£©¡£
ÏÂÃ棬²¹³ä¼¸¸ö£¬ÎÒÈÏΪÓë±¾ÎĺóÐøÌÖÂÛÏà¹ØµÄ»òÕß¿ÉÒÔ°ïÖú´ó¼ÒÀí½â¼«¶ËÏÖÏóµÄ¶¨Ò壺
¹æÔ¼ÐÎʽµÄ¸¡µãÊý:Èç¹û¸¡µãÊýÖÐÖ¸Êý²¿·ÖµÄ±àÂëÖµÔÚ0 < exponent < 2^(e-1)Ö®¼ä£¬ÇÒβÊý²¿·Ö×î¸ßÓÐЧ루¼´ÕûÊý×Ö£©ÊÇ1£¬ÄÇôÕâ¸ö¸¡µãÊý½«±»³ÆΪ¹æÔ¼ÐÎʽµÄ¸¡µãÊý¡£Ò²¾ÍÊÇ£¬Ñϸñ°´ÕÕÎÒÃÇÉÏÎÄÃèÊö±àÂëµÄÊý×Ö¡£
·Ç¹æÔ¼ÐÎʽµÄ¸¡µãÊý:Èç¹û¸¡µãÊýµÄÖ¸Êý²¿·ÖµÄ±àÂëÖµÊÇ0£¬Î²ÊýΪ·ÇÁ㣬ÄÇôÕâ¸ö¸¡µãÊý½«±»³ÆΪ·Ç¹æÔ¼ÐÎʽµÄ¸¡µãÊý¡£IEEE 754±ê×¼¹æ¶¨£º·Ç¹æÔ¼ÐÎʽµÄ¸¡µãÊýµÄÖ¸ÊýÆ«ÒÆÖµ±È¹æÔ¼ÐÎʽµÄ¸¡µãÊýµÄÖ¸ÊýÆ«ÒÆÖµ´ó1.ÀýÈ磬×îСµÄ¹æÔ¼ÐÎʽµÄµ¥¾«¶È¸¡µãÊýµÄÖ¸Êý²¿·Ö±àÂëֵΪ1£¬Ö¸ÊýµÄʵ¼ÊֵΪ-126£»¶ø·Ç¹æÔ¼µÄµ¥¾«¶È¸¡µãÊýµÄÖ¸ÊýÓò±àÂëֵΪ0£¬¶ÔÓ¦µÄÖ¸Êýʵ¼ÊÖµÒ²ÊÇ-126¶ø²»ÊÇ-127¡£Êµ¼ÊÉϷǹæÔ¼ÐÎʽµÄ¸¡µãÊýÈÔÈ»ÊÇÓÐЧ¿ÉÒÔʹÓõģ¬Ö»ÊÇËüÃǵľø¶ÔÖµÒѾСÓÚËùÓеĹæÔ¼¸¡µãÊýµÄ¾ø¶ÔÖµ£»¼´ËùÓеķǹæÔ¼¸¡µãÊý±È¹æÔ¼¸¡µãÊý¸ü½Ó½ü0¡£¹æÔ¼¸¡µãÊýµÄβÊý´óÓÚµÈÓÚ1ÇÒСÓÚ2£¬¶ø·Ç¹æÔ¼¸¡µãÊýµÄβÊýСÓÚ1ÇÒ´óÓÚ0.
ÉÏÃæµÄÁ½¸ö¸ÅÄ¼¸ºõÊÇÖ±½Ó´ÓwikipediaÉÏ°ÇÏÂÀ´µÄ£¬·Ç¹æÔ¼ÐÎʽµÄ¸¡µãÊý³öÏÖµÄÒâÒåÊDZÜÃâͻȻʽÏÂÒç³ö£¨abrupt underflow£©£¬¶ø²ÉÓý¥½øʽÏÂÒç³ö¡£ÕâÒѾÊÇÉÏÊÀ¼Í70Äê´úµÄÊÂÇéÁË£¬²î²»¶àÊÇÎÒµÄÄêÁäµÄÁ½±¶ÁË¡£Õâ¸öÊÇһЩ·Ç³£¼«¶ËµÄÇé¿ö£¬ÔÚ´ËÎÒ³¢ÊÔ×î¼òµ¥µØÃèÊöһϷǹæÔ¼ÐÎʽµÄ¸¡µãÊý³öÏÖµÄÒâÒ壬֪µÀÓÐÕâô»Øʱã¿É£ºÏÂÃ棬ÒÔµ¥¾«¶ÈΪÀý£¬Èç¹ûûÓзǹæÔ¼ÐÎʽµÄ¸¡µãÊý£¬ÄÇô¾ø¶ÔÖµ×îСµÄÁ½¸öÏàÁڵĸ¡µãÊýÖ®¼äµÄ²îÖµ½«ÊǾø¶ÔÖµ×îСµÄ¸¡µãÊýµÄ2^23·ÖÖ®Ò»£¬´ó¼ÒÏëһϣ¬¾ø¶ÔÖµ´ÎСµÄ¸¡µãÊý¼õÈ¥¾ø¶ÔÖµ×îСµÄ¸¡µãÊýµÄÖµÊǶàÉÙ£¿
1.00...01 × 2^(-126) - 1.00...00 × 2^(-126) = 0.00..01 × 2^(-126) = 1 × 2^(-126-23) = 2^(-149)
ºÜÃ÷ÏÔ£¬¾ø¶ÔÖµ×îСµÄ¹æÔ¼ÊýÎÞ·¨±í´ïÆäºÍ´ÎСµÄ¹æÔ¼ÊýµÄ²îÖµ£¬ËùÒÔºÜÈÝÒ×µ¼ÖÂÓÐÈô¸ÉÊý×ÖÖ®¼äµÄ²îÖµÏÂÒ磬¿ÉÄܻᴥ·¢ÒâÁÏÖ®ÍâµÄºó¹û¡£¶øÈç¹û²ÉÓ÷ǹæÔ¼ÐÎʽµÄ¸¡µãÊý£¬Ö¸ÊýÈ«0£¬Æ«ÒÆÖµ±È¹æÔ¼ÊýÆ«ÒÆÖµ´ó1£¨-126±È-127´ó1£©£¬Î²ÊýСÓÚ1£¬ÄÇô·Ç¹æÔ¼ÊýÄܱí´ïµÄ×îСֵ±ãÊÇ£º
0.00..01 × 2^(-126) = 1 × 2^(-126-23) = 2^(-149)
ËùÒÔ£¬·Ç¹æÔ¼ÐÎʽµÄ¸¡µãÊý½â¾öÁËÇ°ÊöµÄͻȻʽÏÂÒç³ö£¨abrupt underflow£©¶ø±»±ê×¼²ÉÄÉ¡£
IEEE 754±ê×¼»¹¹æ¶¨ÁËÈý¸öÌØÊâÖµ£º
- Ö¸ÊýÈ«0ÇÒβÊýСÊý²¿·ÖÈ«0£¬ÔòÕâ¸öÊý×ÖΪ±0¡££¨·ûºÅλ¾ö¶¨Õý¸º£©
- Ö¸ÊýΪ2e – 1ÇÒβÊýµÄСÊý²¿·ÖÈ«0£¬Õâ¸öÊý×ÖÊDZ∞¡££¨·ûºÅλ¾ö¶¨Õý¸º£©
- Ö¸ÊýΪ2e – 1ÇÒβÊýµÄСÊý²¿·Ö·Ç0£¬Õâ¸öÊý×ÖÊÇNaN¡£
½áºÏÇ°ÃæµÄ¹æÔ¼Êý£¬·Ç¹æÔ¼ÊýÒÔ¼°Èý¸öÌØÊâÖµ£¬¿ÉÒԵõ½ÈçÏÂ×ܽ᣺
ÏÖÔÚ£¬ÈÃÎÒÃÇ»ØÒäһϣ¬¸÷ÖÖÓïÑÔÖÐÆÕ±éÃèÊöµÄË«¾«¶È¸¡µãÊýµÄ·¶Î§£º[-1.7 × 10-308,1.7 × 10308]¡£´ò¸ö²í£¬ÏëÏóÒ»¸öÓÐ300¶àλµÄÊ®½øÖÆÊý×ÖµÄÊÊÓÃÇéÐΣ¬Ë½ÒÔΪԶ³¬¹ýÆÕͨÈËÏëÏóÁ¦µÄ±ß½ç¡£Õâ¸ö·¶Î§ÎªÊ²Ã´ÊÇÕâ¸ö·¶Î§ÄØ£¿ÎÒ¾õµÃ£¬Í¨¹ýÉÏÃæµÄÌÖÂÛ£¬´ó¼ÒÓ¦¸ÃÄÜÇåÎú£¬1.7/308ÕâЩÊý×Ö³öÏֵıØÈ»ÔÒò¡£
Ê×ÏÈ£¬ÎÒÃÇÓ¦¸ÃºÜÈÝÒ׸ù¾ÝÆ«ÒÆÁ¿µÃ³öË«¾«¶È¸¡µãÊýµÄ¼ÆË㹫ʽ£º
È»ºó£¬ÒÔÕýÊýΪÀý£¬°´ÕÕÉÏÊöÌØÊâÖµÖб∞ºÍNaNµÄÔ¼¶¨£¬Ö¸ÊýµÄ×î´óÖµÓ¦¸ÃÂú×ãÖ¸ÊýÈ¡¹æÔ¼ÊýµÄÖ¸Êý·¶Î§µÄ×î´óÖµ£¬È»ºóСÊý²¿·ÖȡСÊý²¿·ÖµÄ×î´óÖµ£¬¿ÉÒԵóöÕâ¸ö¶þ½øÖƵÄÊý×ÖÓ¦¸ÃÊÇ£º
0 11111111110 11..11(52¸ö)
ת»»Îª16½øÖƱíʾ£º
0x7fef ffff ffff ffff
ÄÇô£¬¸ù¾ÝÇ°Êö¹æÔ¼ÊýµÄÔÀí£¬·´±àÂë±ãµÃµ½Ê®½øÖƵģº1.7976931348623157 x 10^308¡£ÀàËƵĵÀÀí£¬Signλȡ·´£¬±ãÊÇ·¶Î§µÄÏÂÏÞ¡£
µ½´ËΪֹ°É£¬ÎÒ¶ÔIEEE 754±ê×¼Ò²ÊÇ×î½ü¼¸ÌìÉÔ¼Óѧϰ£¬ÔÙ˵¶àÁ˾ÍÎóµ¼´ó¼ÒÁË¡£Í¨¹ýÕ⼸ÌìµÄѧϰ£¬ÎҸоõ£¬ÎÒÃÇÔÚÀí½âµÄIEEE 754±ê×¼¼°¸¡µãÊýµÄʱºò£¬ÒªÌرð×¢Ò⽫¾«¶ÈºÍ·¶Î§Á½¸ö¸ÅÄî·Ö±ð¿ªÀ´¡£·¶Î§Ö»ÊÇÒ»¸öÄ£ºýµÄ½çÏÞ£¬¾«¶È²ÅÊÇÄÜ׼ȷ±í´ïµÄÊý×Ö¡£
»Øµ½JavaScript
ÔÚÉÏÃæµÄÌÖÂÛÖУ¬ÎÒÃǺÜÉÙÌá¼°JavaScript£¬ËƺõÓе㱳Àë½ñÌìµÄÖ÷ÌâÁË£¬µ«ÊÇ£¬ÔÚÁ˽âÁËÇ°ÊöµÄÔÀíÖ®ºó£¬ÎÒÃǶÔJavaScriptÖÐÊý×ֵİÑÎÕ½«”Ë®µ½Çþ³É”¡£ÕâÖÕ½«ÊÇÒ»´Î£¬Æ̵æ¶àÓÚÕýÎÄ£¬¿ªÎ¸²Ë¶àÓÚÕý²ÍµÄÌÖÂÛ¡£àÅ£¬¿ìº°Ð¡»ï°é£¬Õý²Í¿ªÊ¼ÁË£¡
ESµÄ”The Number Type”£º
ÏÖÔÚ£¬ÎÒÃÇ´ò¿ªES¹æ·¶µÄ“The Number Type”ÊDz»ÊÇ»ù±¾Í¨¶ÁÏÂÀ´ÁË£¿
±ÈÈ磺
The Number type has exactly 18437736874454810627 (that is, 264 − 253+ 3) values…
ΪʲôÊÇÕâ¸öÊý×Ö£¿ÒòΪ£¬ÎÒÃÇ˵JavaScriptÖеÄÊý×ÖÊÇ64-bitsµÄË«¾«¶È£¬ËùÒÔÊ×ÏÈÓÐ2^64ÖпÉÄܵÄ×éºÏ£¬È»ºó£¬°´ÕÕÇ°ÊöµÄIEEE 754±ê×¼µÄ±ê×¼ÖеÄÌØÊâÖµÖеIJ¿·Ö£¬NaNºÍ±∞Õ¼ÓÃÁË2^53¸öÊýÖµ£¬µ«ÊDZíʾÁËÈý¸öÖ±¹ÛµÄÁ¿£¬ËùÒÔ£¬¼Ó¼õһϣ¬×ÔÈ»¾ÍÊÇ18437736874454810627 (that is, 2^64 − 2^53 + 3) values¡£
…the 9007199254740990 (that is, 253−2) distinct “Not-a-Number” values…
ΪʲôÕâô¶àNaN£¿Í¬Ñù£¬°´ÕÕÇ°ÊöµÄIEEE 754±ê×¼µÄ±ê×¼ÖеÄÌØÊâÖµÖеIJ¿·Ö£¬NaNʹÓÃÁËSignificand·ÇÁã¡¢Ö¸ÊýÊÇÌض¨2^e-1ÇÒSignÎÞÒªÇóµÄËùÓпÉÄÜ£¬¼´2^53¼õÈ¥±∞Á½ÖÖÇé¿ö¡£
…e is an integer ranging from −1074 to 971…
ΪʲôָÊýµÄ·¶Î§ÊÇÕâ¸öÄØ£¿¶ø²»ÊÇ-1022µ½+1022ÄØ£¿ÒòΪ£¬ESÑÝ»¯ÁËһϹ«Ê½£¬¶Ô±ÈÒ»ÏÂÎÒÃÇ֮ǰÑÝʾ64-bitsµÄ¹«Ê½£¬¹ØÓÚ²ÎÓë¼ÆËãµÄmantissa£¬ÎÒÃÇ°´ÕÕIEEE 754±ê×¼ÔÚÑÝʾµÄʱºòÖÐʹÓõÄÊÇ1.m£¬¶øES¹æ·¶ÖÐʹÓõÄÊÇm£¬µ±È»»áÓÐβÊýÓòbit³¤¶ÈµÄ²îÒìÁË¡£
µ½ÕâÀ¹ØÓÚÊý×Ö£¬´ó¸Å¾Í¿ÉÒÔ½áÊøÁË¡£¿ªÆªµÄ¼¸¸öÎÊÌ⣬ÏàÐŶÁµ½ÕâÀïµÄͬѧ£¬¶¼ÄÜÓдð°¸ÁË¡£µ«ÊÇ£¬»¹ÓÐÒ»¸öÎÊÌ⣬JavaScriptÖеÄÊý×ÖÕæµÄÖ»ÓÐÒ»ÖÖÀàÐÍÂ𣿣¬¶øÇÒòËƵ½ÏÖÔÚÓëÎÒÃǵijõÖÔ£¬Àí½â>>>ÓеãÆ«ÀëÁË¡£²»¹ý£¬ÊÀ½çÉϺܶàÊÂÇéÍùÍù¶¼ÊÇÕâÑù£¬½âÊÍÔÀíÐèÒªµ½¿Ú¸ÉÉàÔ¶øÓÃÔÀíÈ¥½âÊÍÏÖÏóÈ´Ö»ÐèÒªÈýÑÔÁ½Óï¡£
JavaScript²»ÊÇÖ»ÓÐ64-bitsµÄË«¾«¶È
Êǵģ¬Ð¡±êÌâÒѾ»Ø´ðÁËÎÒÃǵÄÎÊÌ⣬JavaScript²»ÊÇÖ»ÓÐ64-bitsµÄË«¾«¶È¡£ÎÒÃÇͨƪ¶¼ÔÚ˵JavaScriptÖÐÊý×ֵĸ÷ÖÖ£¬Ò»Ö±°´ÕÕ64-bitsµÄË«¾«¶ÈÀ´ÃèÊö£¬µ«ÊÇ£¬Èç֮ǰËù˵£¬ESÖÐÓÐToInteger/ToInt32/ToUint32/ToUint16µÈType Conversion¡£ÕâЩType Conversion²»ÊÇÎÒÃÇÖ±½Óµ÷ÓõÄAPI£¬¶øÊÇÓïÑÔÒýÇæÔÚ½øÐÐijЩÌض¨²Ù×÷µÄʱºò£¬ÌæÎÒÃÇ×öµÄ¡£ÕâÖÖ“ÒþÐεIJÙ×÷”£¬Ö»ÓÐÔÚһЩ¼«¶ËµÄÇé¿öÏ£¬»á±íÏÖ³öÀ´¡£ÏÖÔÚ£¬ÎÒÃÇ¿ÉÒÔµ½“ToInt32”/“ToUint32”/“ToInt16”Èý¸öµØ·½¿´Ò»Ï£¬ÉÔ×÷±È½Ï±ãÄÜ·¢ÏÖ£¬ËûÃǵIJîÒìºÜС£¬Ö»ÊÇÔÚÌض¨µÄ²½ÖèÖдæÔÚ²îÒì¡£±ÈÈ磬ToUint32ºÍToUint16
µÄ²îÒì½ö½ö²Ù×÷µÄ×îºóÒ»²½´æÔÚ²îÒ죬°´Ë³ÐòÁгö±È½Ïһϣº
Let int32bit be posInt modulo 232; that is, a finite integer value k of Number type with positive sign and less than 232 in magnitude such that the mathematical difference of posInt and k is mathematically an integer multiple of 232.
Return int32bit.
vs
Let int16bit be posInt modulo 216; that is, a finite integer value k of Number type with positive sign and less than 216 in magnitude such that the mathematical difference of posInt and k is mathematically an integer multiple of 216.
Return int16bit.
±È½Ïһϣ¬²»ÄÑ·¢ÏÖ£¬½ö½öÊÇ2^32ºÍ2^16µÄ²îÒ죬¶ø¹Ø¼üµãÇ¡ÊÇmodulo²Ù×÷µÄʱºò£¬°´ÕÕÎÒÃÇ֮ǰÌÖÂÛµÄÔÀí£¬ºÜÈÝÒ×Àí½âÕâ¸ö²Ù×÷¾ö¶¨ÁË¿ÉÄܳöÏÖµÄ×î´óÊý¡£ÕâÑùµÄ±È½Ï£¬ÓÐÒ»ºÃ´¦£¬ÄÜÌá¸ßÎÒÃÇÔĶÁ±ê×¼µÄËٶȣ¬¶øÇÒ¼ÓÉîÀí½â£¬¶ÔÕÆÎÕ±ê×¼ºÜÓаïÖú¡£
×ܽáÒ»ÏÂÕâÈý¸ö²Ù×÷µÄ·¶Î§£º
ToInt32µÄ·¶Î§±ãÊÇÆäËüÇ¿ÀàÐÍÓïÑÔÖеÄ[-231, -231 – 1]¡£
ToUint32µÄ·¶Î§±ãÊÇÆäËüÇ¿ÀàÐÍÓïÑÔÖеÄ[0, -232 – 1]¡£
ToUint16µÄ·¶Î§±ãÊÇÆäËüÇ¿ÀàÐÍÓïÑÔÖеÄ[0, -216 – 1]¡£
ͨ¹ýËÑË÷£¬ºÜÈÝÒ×ÄÜÕÒµ½£¬JavaScriptÖÐÄÇЩ²Ù×÷ÖÐʹÓÃÁËÉÏÊöÏà¹ØµÄ²Ù×÷¡£ÆäÖУ¬ToUint16½ö½öÔÚString.fromCharCodeÖÐÓÐʹÓã¬ÎÒÃDz»×öÌÖÂÛÁË¡£ToInt32ÓÐÔÚ¶à¸öλÔËËã·ûÖÐʹÓ㬱ÈÈç~ / << / >>£¬ÒÔ¼°ÔÚparseIntÒ²ÓÐʹÓ᣶øToUint32µÄʹÓÃÔò³öÏÖÔÚÁË´óÁ¿µÄµØ·½£¬Ö÷Òª·Ö²¼ÔÚ£¬Êý×éÏà¹ØµÄ²Ù×÷£¬Î»ÔËËãµÄ²Ù×÷Á½¸öÇøÓò¡£
ÎÒÃǾͽèToUint32µÄÕâЩʹÓ㬻ص½¿ªÆªÌÖÂÛµÄÄǸöµØ·½°É£º
Ê×ÏÈ£¬À´µ½ÕâÀï>>>£¬¿´µ½²Ù×÷ÈçÏ£º
1.Let lref be the result of evaluating ShiftExpression.
2.Let lval be GetValue(lref).
3.Let rref be the result of evaluating AdditiveExpression.
4.Let rval be GetValue(rref).
5.Let lnum be ToUint32(lval).
6.Let rnum be ToUint32(rval).
7.Let shiftCount be the result of masking out all but the least significant 5 bits of rnum, that is, compute rnum & 0x1F.
Return the result of performing a zero-filling right shift of lnum by shiftCount bits. Vacated bits are filled with zero. The result is an unsigned 32-bit integer.
ÔÙ¿´new Array (len)£¬ÓÐÒ»¾ä£º
If the argument len is a Number and ToUint32(len) is equal to len, then the length property of the newly constructed object is set to ToUint32(len). If the argument len is a Number and ToUint32(len) is not equal to len, a RangeError exception is thrown.
¶Ô±È²»ÄÑ·¢ÏÖ£¬>>>µÄ·µ»ØÖµºÍarray.lengthµÄÈ¡Öµ·¶Î§£¬ÎÞ²îÒ죬¾¹ý>>>²Ù×÷ºóµÄÊý×Ö£¬Ò»¶¨ÊÇÒ»¸öºÏ·¨µÄarray.length¡£½âÊÍÔÀí×ÜÊÇÄÇô¸´ÔÓ£¬¿ÉÊÇÓÃÔÀí½âÊÍÏÖÏó×ÜÊÇÄÇô¼òµ¥¡£
תÔØÇë×¢Ã÷£º ÎÄÕÂתÔØ×Ô£º°®Ë¼×ÊÔ´Íø http://www.aseoe.com/show-12-878-1.html