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
【Go言語】浮動小数点
Search
Tomoki Ota
July 20, 2024
Programming
0
57
【Go言語】浮動小数点
Go言語の浮動小数点について、解説しています。
【Qiita】
【Go言語】浮動小数点
Tomoki Ota
July 20, 2024
Tweet
Share
More Decks by Tomoki Ota
See All by Tomoki Ota
アーキテクチャの価値
tomo1227
0
88
アーキテクチャとビジネスロジック
tomo1227
0
86
【Go言語】テスト
tomo1227
0
50
【Go言語】クロージャ
tomo1227
0
250
【Go言語】イテレータ
tomo1227
0
67
【Go言語】エラーハンドリング
tomo1227
0
56
AIに淘汰されないようにするには?
tomo1227
0
57
【Go言語】range
tomo1227
0
60
【Go言語】break
tomo1227
0
59
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
150
旅行プランAIエージェント開発の裏側
ippo012
1
610
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
100
AIを活用し、今後に備えるための技術知識 / Basic Knowledge to Utilize AI
kishida
19
4.4k
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
1.4k
Flutter with Dart MCP: All You Need - 박제창 2025 I/O Extended Busan
itsmedreamwalker
0
110
Updates on MLS on Ruby (and maybe more)
sylph01
1
170
AI時代のドメイン駆動設計-DDD実践におけるAI活用のあり方 / ddd-in-ai-era
minodriven
25
9.7k
Go言語での実装を通して学ぶLLMファインチューニングの仕組み / fukuokago22-llm-peft
monochromegane
0
110
Google I/O recap web編 大分Web祭り2025
kponda
0
2.9k
ソフトウェアテスト徹底指南書の紹介
goyoki
1
130
Introducing ReActionView: A new ActionView-compatible ERB Engine @ Rails World 2025, Amsterdam
marcoroth
0
310
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
45
7.6k
The Cost Of JavaScript in 2023
addyosmani
53
8.9k
GitHub's CSS Performance
jonrohan
1032
460k
Statistics for Hackers
jakevdp
799
220k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
51
5.6k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
111
20k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Designing Experiences People Love
moore
142
24k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Fireside Chat
paigeccino
39
3.6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Transcript
Tomoki Ota ʲGoݴޠʳුಈখ
f loat32 f loat64 Goͷුಈখܕ 2
Goͷුಈখܕ 3
Goͷුಈখܕ 1.0001 * 1.0001 = 1.00020001 ؙΊޡࠩͰग़ྗ݁Ռ1.0002ʹͳΔ 4
খ : ແݶݸଘࡏ͢Δ f loat64 : ༗ݶɻ64bit Goͷුಈখܕ 5
ූ߸s, ԾF, ࢦeͷͱ͖ͷ10ਐЋ Goͷුಈখܕ α = (−1)s × F ×
2e 6
Goͷුಈখܕ 1.0001 = 1 × 1.000100016593933 × 20 ූ߸s, ԾF,
ࢦeͷͱ͖ͷ10ਐЋ 7
୯ਫ਼ුಈখ( f loat32) : ࢦ8ϏοτɺԾ23Ϗοτ ഒਫ਼ුಈখܕ( f loat64) : ࢦ11ϏοτɺԾ52Ϗοτ
Goͷුಈখܕ 8
Goͷුಈখܕ ූ߸ ࢦ(8bit) Ծ(23bit) 0 1111111 00000000000001101000111 9
ൺֱ ϓϩηοαʹґଘ͢Δ ಛघͳුಈখ ޡࠩͷੵ ۙࣅΛ͏͜ͱʹΑΔฐ 10
ۙࣅΛ͏ͱɺ==Λ༻ͨ͠ൺֱ͕ෆਖ਼֬ʹͳΔ߹ ͕͋Δɻ goͷςετϥΠϒϥϦtestify ʹൺֱ͍ͯ͠Δ͕Ўͷ ൣғͰ͋Δ͜ͱΛݕࠪ͢ΔͨΊͷInDelta͕ଘࡏ͢Δɻ ൺֱ 11
ϓϩηοαʹɺුಈখԋࢉΛॲཧ͢Δුಈখԋࢉ Ϣχοτ(Floating Point Unit, FPU)͕͋Δɻ ॲཧ݁ՌFPUʹґଘ͢ΔͷͰɺFPU͕ҟͳΔผͷϚγϯͰ ಉ݁͡ՌʹͳΔอূͳ͍ɻ ͪ͜Β 𝛿 Λߟ͑Δ͜ͱͰղܾ͢Δɻ
ϓϩηοαʹґଘ͢Δ 12
ϓϩηοαʹɺුಈখԋࢉΛॲཧ͢Δුಈখԋࢉ Ϣχοτ(Floating Point Unit, FPU)͕͋Δɻ ॲཧ݁ՌFPUʹґଘ͢ΔͷͰɺFPU͕ҟͳΔผͷϚγϯͰ ಉ݁͡ՌʹͳΔอূͳ͍ɻ ͪ͜Β 𝛿 Λߟ͑Δ͜ͱͰղܾ͢Δɻ
ಛघͳුಈখ 13
• ਖ਼ͷແݶେ • ෛͷແݶେ •NaN(Not-a-Number) ಛघͳුಈখ 14
NaNf != fΛຬͨ͢།Ұͷුಈখ ಛघͳුಈখ 15
ಛघͳුಈখ 16
ಛघͳුಈখ ͜ΕΒ3ͭͷුಈখʹ͍ͭͯͷൺֱɺ math.IsInf(ແݶ)Ͱɺmath.IsNan(NaN)ͰൺֱͰ͖ Δɻ 17
ޡࠩͷੵ(Ճࢉɾݮࢉ) 10000ʹ1.0001ΛnճՃࢉ͢ΔϓϩάϥϜ 18
ޡࠩͷੵ(Ճࢉɾݮࢉ) 1.0001ΛnճՃࢉͯ͠ɺ࠷ޙʹ10000ΛՃࢉ͢ΔϓϩάϥϜ 19
ޡࠩͷੵ(Ճࢉɾݮࢉ) n ਖ਼֬ͳ f1 f2 10 10010.001 10010.001 10010.001 1K
11000.1 11000.0999999993 11000.1 1M 1.0101E+06 1.01009999997614E+06 1.01009999997668E+06 ՃࢉݮࢉΛ࿈ଓͯ͠ߦ͏߹ɺେ͖͞ͷ͍ۙΛ·ͱΊͯܭࢉ͔ͯ͠Β େ͖ͳΛՃࢉɾݮࢉ͢Δͱɺޡ͕ࠩখ͘͞ͳΔɻ 20
ޡࠩͷੵ(ࢉɾআࢉ) a × (b + c) a × b +
a × c v.s. 21
ޡࠩͷੵ(ࢉɾআࢉ) a × (b + c) a × b +
a × c v.s. 22
ޡࠩͷੵ(ࢉɾআࢉ) a × b + a × c ͷํ͕ޡ͕ࠩগͳ͍ ՃࢉɾݮࢉΑΓࢉɾՃࢉΛઌʹߦ͏ͱ
ޡࠩΛখ͘͢͞Δ͜ͱ͕Ͱ͖Δ 23
Goͷ f loat32, f loat64ۙࣅΛͱΔͷͰɺޡ͕ࠩൃੜ͢Δ Ճࢉɾݮࢉಉܻ͡ͷԋࢉΛ·ͱΊͯߦ͏͜ͱͰɺਫ਼্͕͕Δ ࢛ଇԋࢉ͕ࠞ߹͢Δ߹ɺࢉͱআࢉΛઌʹߦ͏͜ͱͰɺਫ਼্͕͕Δ ·ͱΊ 24