Swift for Beginners Part 16 - Ints, Floats, Doubles

preview_player
Показать описание
iOS Academy offers the #1 course for iOS Development for Beginners. Learn to create iPhone and iPad apps from scratch. Everyone these days has an app idea; learn the important skill of making those apps, make yourself more marketable, change industries to get a different job, and enjoy the ride!

Рекомендации по теме
Комментарии
Автор

"A Double is an Integer with two decimal places." - Uhm, hard no. A Double is a Float with twice the number (hence "double") of bits i.e. precision, which is why it's also called a "double-precision floating point" type.
* A regular floating point value of type "Float" uses 32 bits of memory, Swift also knows it as Float32.
* A double-precision floating point value uses 64 bits of memory, i.e. twice/DOUBLE the number of bits, allowing for more post-comma decimal places i.e. better precision, Swift also knows it as Float64.
* What's more, Swift also knows the Float80 type, which is "more than juste double the precision of a regular Float32" and uses 80 bits of memory; in C/C++ the Float80 would be known as the "long double" type, you could alternatively utilize it in Swift via the CLongDouble keyword.

bm
Автор

I think you have doubles and floats mixed up since doubles hold more decimal points than floats.

EthanZemelman
Автор

I've been enjoying these videos. I've managed to hack my way through some Swift development, and these videos provide really great context to help me understand what was happening under the hood. 

One problem: The difference between double and float doesn't have anything to do with the number of decimal places; it's the number of bits used to store it. A float usually uses 32 bits and can hold 7 significant digits, while a double uses 64 bits and can hold 15 significant digits. For example if you define a float as 123456.789, it will only store 123456.8. To keep the full precision, you would have to use a double.

Thanks for the videos.

jeffgeorge