Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ecmascript BigInt
Search
Taketoshi Aono(青野健利 a.k.a brn)
August 24, 2017
Programming
3
490
Ecmascript BigInt
Ecmascript で導入されそうなBigInt型についてです。
Taketoshi Aono(青野健利 a.k.a brn)
August 24, 2017
Tweet
Share
More Decks by Taketoshi Aono(青野健利 a.k.a brn)
See All by Taketoshi Aono(青野健利 a.k.a brn)
document.write再考
brn
5
2.5k
Parsing Javascript
brn
12
6.9k
JSON & Object Tips
brn
1
280
CA 1Day Youth Bootcamp for Frontend LT
brn
0
660
Modern TypeScript
brn
2
680
javascript - behind the scene
brn
3
590
tc39 proposals
brn
0
640
プロダクト開発とTypeScript
brn
8
2.7k
React-Springでリッチなアニメーション
brn
1
490
Other Decks in Programming
See All in Programming
ファイル先頭の use の意味、説明できますか? 〜PHP の namespace と autoloading の関係を正しく理解しよう〜 / namespace and autoloading in php
okashoi
2
470
WebComponentsで フレームワークを1ページに共存させる
webuilder240
0
150
AppDeveloperCon 2024 EU: Building polyglot developer experiences in 2024
salaboy
0
380
Cloud RunとCloud PubSubでサーバレスなデータ基盤2024 with Terraform / Cloud Run and PubSub with Terraform
shinyorke
7
1.9k
GitHub Copilot Tips and Tricks
yuichielectric
26
7.5k
Migrating to Signals: A Practical Workshop
manfredsteyer
PRO
0
290
DDD, necessary but insufficient: physical design principles for microservices
cer
PRO
0
2.2k
Kotlinを用いたDSL的な設計手法と使用上の注意
kohii00
3
530
LLMチャットボットのアプリケーション設計Tips
os1ma
4
660
Laravel標準バリデーションでできること
hmb_ok
2
360
今の SmartHR にエンジニアで入社するとどうなるの?
daisukeshinoku
3
1.8k
OpenAPI を守るのは難しい
ohmori_yusuke
1
140
Featured
See All Featured
How GitHub (no longer) Works
holman
301
140k
Making the Leap to Tech Lead
cromwellryan
123
8.4k
Build your cross-platform service in a week with App Engine
jlugia
223
17k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
153
14k
It's Worth the Effort
3n
180
27k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
1
3.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
319
23k
The Cult of Friendly URLs
andyhume
73
5.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
397
65k
Teambox: Starting and Learning
jrom
126
8.4k
Happy Clients
brianwarren
91
6.3k
Transcript
Ecmascript BigInt
せ: @brn (ꫬꅿ⨳ⵃa.k.a ـٕ٦ظ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥iOSؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger
ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn
Integer or Number… JavascriptךNumber㘗כ⦓侧䏝㼭侧挿㘗կ ׃גծך剑㣐⦼כ53Bitⴓ2 ^ 53 – 1կ ׁחؽحز怴皾遤ֲ㜥さכ32Bit侭侧ח㢌䳔ׁծ
2 ^ 32הזկ
Double Precision Floating Point ⦓礵䏝嵤⹛㼭侧挿侧(DPFP)כ㼰侧12345 ה 10 ^ xחⴓֽג罋ִ 邌植倯岀կ
DPFPכIEEE 754ח״ג⟃♴ך״ֲח㹀纏ׁגְկ 52 11 1 ˟⽃⡘כׅץגؽحز 䊩ַծ痗〾ؽحز٥䭷侧鿇٥⟎侧鿇הְֲせחזגְկ
Double Precision Floating Point A. 痗〾ؽحزהכ1bit⢪ג⦼ָ +ַ-邌植ׅկ B. 䭷侧鿇הכ11ؽحز⢪ג10ך⛦ 皾邌植ׅկ
C. ⟎侧鿇כ53ؽحزך侭侧⦼邌植 ׅկ ׅה⟃♴ך״ֲח㼰侧邌植ֿׅ הָדֹկ (A? +1 : -1) * (C * (10 ^ B))
MAX_SAFE_INTEGER Ecmascriptחכֿך⦓礵䏝嵤⹛㼭侧挿侧ך眔㔲ד㸜Ⰻח鎘皾דֹ ⦼ךMax⦼㹀גֶծ Number.MAX_SAFE_INTEGERה׃ג،ؙإأֿׅהָ〳腉կ ׃גך⦼כ鶢ך(2 ^ 53 – 1)הזկ זזIEEE
754ךDPFPדכ⟎侧鿇ָ52ؽحز׃ַזְַկ
Limitation ׃ַ׃ծMAX_SAFE_INTEGER馄ִ侧⦼ד怴皾׃ְ㜥さכ וֲׅךַ npmٌآُ٦ٕ⢪ֲ • substack/node-bitint • peterolson/BigInteger.js
var bigint = require('bigint');! ! var b = bigint('782910138827292261791972728324982')! .sub('182373273283402171237474774728373')!
.div(8);! ! console.log(b);!
Operator Problem 铣חְֻ… JSכぐ珏怴皾㶨ؔ٦غ٦ٗ٦سדֹזְךדծ 杝荈侧⦼ؙٓأחכַז搀椚ָ֮կ
Ecmascript BigInt ֿדtc39 proposalחEcmascript BigIntָ䲿周ׁկ 植㖈stage3זךדֲ㼰׃ד䱰欽גٓ؎ٝկ
BigInt Overview BigIntכSignedהUnsignedך64bit侭 侧⦼ד邌植ׁկ 侧⦼ٔذٕٓך䖓חn אֽֿה דBigIntٔذٕٓ邌植ׅկ HexװOctalٔذٕٓ؟ه٦زկ侧⦼ ٔذٕٓהずֻׄn劣㽵חאֽֿ הדBigIntחזկ(׃ծOctalכ
0oXXX䕎䒭ך) תծtypeof <bigint>כ 'bigint'ָ䨱կ
function nthPrime(nth) {! function isPrime(p) {! for (let i =
2n; i < p; i++) {! if (p % i === 0n) return false;! }! return true;! }! for (let i = 2n; ; i++) {! if (isPrime(i)) {! if (--nth === 0n) return i;! }! }! }!
BigInt Operators 怴皾㶨כغ؎شٔؔلٖ٦ة٦ + - * ** / % הծ
ぐ珏ؽحز怴皾| & << >> ^ הծ 嫰鯰怴皾㶨 == === < > >= <= ؟ه٦زկ ׃ծ0㙵怴皾㶨 >>> כ؟ه٦ ز׃זְկ
BigInt Objects Number㘗ך״ֲחٓحػ٦ؔـآؙؑزךBigIntؔـآؙؑز欽 䠐ׁկ 䔲搫Constructor欽䠐ׁկ ConstructorכNumberך״ֲח俑㶵װך➭ך㘗BigIntח㢌䳔 ׅկ
new BigInt('34034')! // BigInt {[[PrimitiveValue]]: 34034n}! // new でオブジェクトを生成 !
BigInt('34034')! // 34034n! // 関数呼び出しで変換 ! BigInt.asUintN(width, BigInt)! // 引数BigIntを 0 から 2 ^ widthのサイズのBigIntに変 換する。 ! BigInt.asIntN(width, BigInt)! // 引数BigIntを -2 ^ width から 2 ^ (width - 1) - 1のサイズのBitInt型に変換する。 ! BigInt.parseInt(string[, radix])! // 文字列をradixを基数とするBigInt型に変換する。
BigInt Limitation Number㘗הך幉さכ鏩〳ׁזְկ אתծぐ珏怴皾㶨כBigIntず㡦ד׃ ַ㹋遤דֹזְկ JSךDPFPהך怴皾ך穠卓ָIntegerח זזְךדBigIntך⥂鏾㢩חזג ׃תֲկ את农럀ך㢌䳔כ♧ⴖ遤זְկ ׃ծ嫰鯰怴皾ך幉さֿׅהָ
鏩〳ׁגְկ
TypedArray ׁחTypedArrayח BigInt64ArrayהBigUint64Array㘗ָ鷄⸇ׁ կ Int64הUint64㘗ד侧⦼⥂䭯ׅկ
DataView DataViewח get/set BigInt64 ًاحسָ鷄⸇ׁגծ⦼BitInt㘗ה׃ג《⳿ׇ״ֲחזկ
תה װהjavascriptח64bit侭侧ֹתׅיկ ׀幠耮ָ֮הֲ׀ְׂת׃