Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Numbers in javascript

Numbers in javascript

JSのNumberについて

More Decks by Taketoshi Aono(青野健利 a.k.a brn)

Other Decks in Programming

Transcript

  1. Numbers in javascript

    View full-size slide

  2. Name
    @brn (ꫬꅿ⨳ⵃ)
    Occupation
    ؿٗٝزؒٝسؒٝآص،٥ط؎ذ؍ـؒٝآص،
    Company
    Cyberagent ،سذؙأةآؔ AI Messenger
    OSS
    Contributor of V8
    About
    http://info.b6n.ch

    View full-size slide

  3. Number
    ES2016~2018׾穗גjavascriptך侧⦼㘗ח׮
    ְֻאַ㢌⻉ָ֮׏׋ךד׉ך鑧

    View full-size slide

  4. Variations
    -  侭侧
    -  㼭侧
    -  16鹌侧
    -  8鹌侧
    -  2鹌侧
    -  Bigint
    -  Separator

    View full-size slide

  5. 侭侧
    64bitתדך侭侧׾䪔ִ׷
    ⰻ鿇涸חכ㹋鄲⣛㶷׌ָ31bit侭侧ה64bit Doubleדⴽ׸גְ׋׶ծ
    64bit Doubleך׫׌׏׋׶

    View full-size slide

  6. 㼭侧
    㼭侧挿
    הֻח鎉ֲֿה׮זְָծⰻ鿇涸חכ64bit DoubleדⳢ椚ׁ׸׷
    זךד鎘皾穠卓כ鵚⡂⦼חז׷

    View full-size slide

  7. 16鹌侧
    0xדכׄת׷侧⦼
    CSSהַדֶזׄ׫

    View full-size slide

  8. 8鹌侧
    0oדכׄת׷ַ
    0~ד7⟃♳ך侧⦼ָזְ㜥さח8鹌侧חז׷
    ؿ؋؎ٕػ٦ىحءّٝהַדֶזׄ׫

    View full-size slide

  9. // 8進数!
    0o777!
    !
    // 暗黙の8進数
    0777!
    !
    // 0から始まる10進数
    0778!
    !
    "use strict";!
    0777 // Error!!

    View full-size slide

  10. 2鹌侧
    0bַ׵㨣ת׷0ה1ך׫⢪欽〳腉זٔذٕٓ

    View full-size slide

  11. // 2進数!
    0b11101101 // 237!

    View full-size slide

  12. BigInt
    64bit⟃♳ך侧⦼׾䪔ֲ㜥さח⢪ֲ
    植㖈Stage3
    侧⦼ٔذٕٓך䖓׹ח n ׾אֽ׷ֿהדBigIntٔذٕٓ׾邌植ׅ׷կ
    HexװOctalٔذٕٓ׮؟ه٦زկ侧⦼ٔذٕٓהずֻׄn׾劣㽵ח
    אֽ׷ֿהדBigIntחז׷կ(׋׌׃ծOctalכ0oXXX䕎䒭ך׫)
    ת׋ծtypeof כ 'bigint'ָ䨱׷կ

    View full-size slide

  13. // Bigint!
    10n + 10n // 20n!
    10n + 10 // Error!
    typeof 10n // 'bigint'!
    BigInt('100') // 100n!

    View full-size slide

  14. BigInt
    鑫׃ֻכ
    https://speakerdeck.com/brn/ecmascript-bigint
    ח剅ְ׋

    View full-size slide

  15. Separator
    植㖈Stage3
    ת׌mergeׁ׸גְזְָV8ח㹋鄲׃ג׫׋
    ׉ךֲ׍⢪ִ׷״ֲחז׷ծ✮㹀

    View full-size slide

  16. // Numeric Separators!
    1_0_0_0_0!
    0xFF_FF_FF!
    0b1000_1111_0000!
    0o7_7_7!
    !
    1__0 // Error!
    1000_ // Error!

    View full-size slide

  17. ׀幠耮֮׶ָהֲ׀ְׂת׃׋

    View full-size slide