flight-school / guide-to-swift-numbers-sample-code Goto Github PK
View Code? Open in Web Editor NEWXcode Playground Sample Code for the Flight School Guide to Swift Numbers
Home Page: https://flight.school/books/numbers
License: MIT License
Xcode Playground Sample Code for the Flight School Guide to Swift Numbers
Home Page: https://flight.school/books/numbers
License: MIT License
The book is fantastic as usual but it contains a classic mistake in the Money type: The ExpressibleByFloatLiteral
fallacy :)
This undos all of the good intentions of having exact values in the type.
let m = Money<USD>(floatLiteral: 0.14)
m.amount
Here m.amount
is now 0.14000000000000002048 which is clearly not exact anymore.
The reason I guess is that the literal is always first converted to a Float
, and only then to a Decimal
.
If you want any literal initialization, you need to use the String initializer because Decimal(string: "0.14")
is indeed 0.14 now.
See my related Swift post
https://forums.swift.org/t/exact-nsdecimalnumber-via-literal/12834
and tracking bugs:
https://bugs.swift.org/browse/SR-3317
https://bugs.swift.org/browse/SR-920
Sure one can argue "but for the purpose of this book…" but that's not what the Flight School books are about. They are precise, and that's what makes them so darn good.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.