![]() Helpfully, Swift even warns us when this happens. In fact, there are certain numbers that Double isn’t even able to hold, so instead it stores a very slightly different value. The problem is that although Double uses the same amount of memory to store its value as Int, the way it stores its data is a little fuzzy – it has really great precision with smaller numbers, but increasingly fuzzy precision when you start working with large numbers. Now, you might then think “well, how about when we add an Int to a Double we get back a new Double that can store all the data?” And that’s a great question! So, at the simplest level you can see that adding a Double to an Int isn’t safe because the Double can store things the Int can’t and that would be lost in the resulting integer. For example, both Double and Int take the same amount of memory to store their number, but Int only stores whole numbers whereas Double can store values after the decimal place. Swift has these different numerical types because they store their data differently. But when it comes to working with numbers, it has several very specific types, including Double, Float, and Int – there are many more than those, but they are the most commonly used. Swift has a number of ways of storing data, such as strings, Booleans, and arrays.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |