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
Decimal、正しく使ってる? / Are you using Decimal correc...
Search
Elvis Shi
December 15, 2021
Programming
4
690
Decimal、正しく使ってる? / Are you using Decimal correctly?
Elvis Shi
December 15, 2021
Tweet
Share
More Decks by Elvis Shi
See All by Elvis Shi
How did I build an Open-Source SwiftUI Toast Library
lovee
1
48
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
660
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
240
Observation のあれこれ / A brief introduction about Observation
lovee
3
330
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
26
8.2k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
270
偏見と妄想で語るスクリプト言語としての Swift / Swift as a Scripting Language
lovee
2
790
danger-swift-kantoku
lovee
1
490
A story about me trying to make a router that manages when, how and which view to transit in a SwiftUI app
lovee
1
390
Other Decks in Programming
See All in Programming
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
Click-free releases & the making of a CLI app
oheyadam
2
120
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Quine, Polyglot, 良いコード
qnighy
4
640
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
88
5.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
RailsConf 2023
tenderlove
29
900
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
What's new in Ruby 2.0
geeforr
343
31k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Transcript
%FDJNBMɺਖ਼ͬͯ͘͠Δʁ forJ1IPOF%FW4BQQPSPGFBU)","5"TXJGU
} var employedBy = "YUMEMI Inc." var job = "iOS
Tech Lead" var favoriteLanguage = "Swift" var twitter = "@lovee" var qiita = "lovee" var github = "el-hoshino" var additionalInfo = """ M1 Max MacBook Proࠓಧ͍ͨʂ """ final class Me: Developable, Talkable {
ʲใʳΏΊΈɺ҉߸௨՟Λൃߦʂ ˞ӕͰ͢ɻ
ͱ͍͏Θ͚Ͱ ΏΊΈͷڅ༩:VNF$PJOͰࢧڅʹ ˞ӕͰ͢ɻ
// ࠓ݄ͷڅ༩ var myYumeCoin = 0.2 // ࠓ݄ͷϘʔφε myYumeCoin +=
0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // ߴ֬ೝ print(myYumeCoin) // 0.20000000000000004 ??????
ͳͥ͜Μͳ͜ͱ͕ى͜Δͷ͔ w 4XJGUͰখΛѻ͏ͱ͖ɺσϑΥϧτͰDouble͕ ΘΕΔ w Doubleʮഒਫ਼ුಈখʯͳͷͰɺਫ਼ͷ Ͱͦͦਖ਼֬ʹදͤͳ͍ࣈ͕ͨ͘͞Μ͋Δ w େͷ߹ͦͷؙΊΒΕͨࣈͰʹͳΒͳ͍ ͕ɺۚ༥ܥͳͲͷ߹ਖ਼֬ʹѻ͏ඞཁ͕͋Δ
Decimal
Decimalܕ w ුಈখΛेਐϕʔεͰѻ͏ͨΊͷܕ w ༗ޮܻ͕ܻ w ༗ޮܻൣғͰ͋Εेਐදهͷޡ͕ࠩͳ͍
// ࠓ݄ͷڅ༩ var myYumeCoin = 0.2 // ࠓ݄ͷϘʔφε myYumeCoin +=
0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // ߴ֬ೝ print(myYumeCoin) // 0.20000000000000004 ??????
import Foundation // ࠓ݄ͷڅ༩ var myYumeCoin: Decimal = 0.2 //
ࠓ݄ͷϘʔφε myYumeCoin += 0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // ߴ֬ೝ print(myYumeCoin) // 0.2 🎉 'PVOEBUJPO͕ඞཁ ܕΛ໌ࣔతʹ%FDJNBMʹࢦఆ
DecimalɺŜƃŤƄƃŬžŜŘŢŦ
DecimalɺŜƃŤƄƃŬžŜŘŢŦ ͱɺࢥͬͨʁ
import Foundation // ࠓ݄ͷڅ༩ var myYumeCoin: Decimal = 0.2 //
ࠓ݄ͷϘʔφε myYumeCoin += 0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // ߴ֬ೝ print(myYumeCoin) // 0.2 🎉
import Foundation // ࠓ݄ͷڅ༩ var myYumeCoin: Decimal = 0.2 //
ࠓ݄ͷϘʔφε myYumeCoin += 0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // Decimal Λͬͯਖ਼֬ͳڅ༩ܭࢉ͕Ͱ͖͔ͨΒ͍͑Ϙʔφεʂ myYumeCoin += 123.456 // ߴ֬ೝ print(myYumeCoin) // 123.65599999999997952 !!!?????
DecimalɺūŬŹƂŜŽūŘ
DecimalͷϦςϥϧೖ w খϦςϥϧͰDecimalΛೖͰ͖Δͷɺ ExpressibleByFloatLiteralΛར༻ͨ݁͠Ռ w ࣮init(floatLiteral value: Double) w DecimalΛ࡞ΔલʹͦͦઌʹҰճDoubleΛ
࡞ͬͯͦͷ݁ՌΛೖ͍ͯ͠Δ͚ͩʂ
খϦςϥϧͰ DecimalΛೖ͠ͳ͍Ͱʂ
%FDJNBMΛखܰʢʁʣʹѻ͏ͨΊͷ ΠχγϟϥΠβʔ • init(_ value: String, format: Decimal.FormatStyle, lenient:
Bool = true) throws // iOS 15+ • init?(string: String, locale: Locale? = nil) // iOS 7+ • // etc…
import Foundation // ࠓ݄ͷڅ༩ var myYumeCoin: Decimal = 0.2 //
ࠓ݄ͷϘʔφε myYumeCoin += 0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // Decimal Λͬͯਖ਼֬ͳڅ༩ܭࢉ͕Ͱ͖͔ͨΒ͍͑Ϙʔφεʂ myYumeCoin += 123.456 // ߴ֬ೝ print(myYumeCoin) // 123.65599999999997952 !!!?????
import Foundation // … // Decimal Λͬͯਖ਼֬ͳڅ༩ܭࢉ͕Ͱ͖͔ͨΒ͍͑Ϙʔφεʂ //myYumeCoin += 123.456
// ࠓͦ͜ʂ myYumeCoin += try! .init("123.456", format: .number) // ߴ֬ೝ print(myYumeCoin) // 123.656 🎉
DecimalɺͪΐͬͱͰ͖͔ͨͳ
ʲࢀߟʳ
IUUQTGPSVNTTXJGUPSHUIPXUPJOJUJBMJ[FEFDJNBM
IUUQTJEFBMSFBMJUZDPNQSPHSBNJOHTXJGUEFDJNBMTUSJOH
ʲએʳ
IUUQTZVNFNJDPOOQBTTDPNFWFOU
IUUQTXXXZVNFNJDPKQDBUFHPSZSFDSVJU