Giter Site home page Giter Site logo

flight-school / guide-to-swift-numbers-sample-code Goto Github PK

View Code? Open in Web Editor NEW
95.0 4.0 6.0 97 KB

Xcode Playground Sample Code for the Flight School Guide to Swift Numbers

Home Page: https://flight.school/books/numbers

License: MIT License

Swift 100.00%
swift numbers floating-point numberformatter measurementformatter money currency

guide-to-swift-numbers-sample-code's People

Contributors

mattt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

guide-to-swift-numbers-sample-code's Issues

Remove faulty float literal initialization from Money type

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.