So far, we've encountered one type of variable, which is a string.
Now there's an important word in there and that's called type.
When you hear people talk about programming languages, you say loosely typed, strongly typed.
In some cases, no types.
What they're referring to is the kind of thing that's stored in memory as a variable.
So to give you a counterexample to the string that we had before it, you can kind of see the remnants
of here.
Hello, playground.
What we're going to do is have a variable number, which is like equal to number eight or something.
Right.
So what is that number type?
Well, it's not a string because it doesn't have the quotes around it.
It's actually an integer, which is a whole number in everyday language.
Now, there are some nuances to integers that you need to be aware of, but we'll get into those as
we move on with the course.
Let's have a var numb to.
Equal to and let's give this a decimal seven point eight.
What kind of number is that?
Well, it's not an integer because it's not a whole number.
This is actually a double, which stores a very long sequence of numbers, depending on the processor
you have in your system, 32 bit or 64 bit.
But basically it's there to do the complex number calculations.
Okay.
And I don't mean complex number in the math sense.
I mean long numbers to basically what else are we going to have here?
Let's have our number three and let's explicitly call this something.
Which is a float now, this is the same thing as a double, we can store decimals in it, but but it
has a much shorter range so we can store fewer decimals.
Now, if I was writing a finance app to do High-Speed Trading on the stock market, I would never use
a float.
I would use the most accurate number because the rounding errors that come from floats will destroy
your application and give you totally incorrect output rates.
That would be an error, obviously.
Now, if you want to know what type of things these are, we can actually call something that's called
type.
Here it is on the second line type of.
And if you just pass in.
Let's say numb, and then we run all of this.
You're going to see this is the integer type.
Right.
And of course, we can do the same with number two.
And the same with number three.
OK, so we have an inch, we have a double and we have a float, so we can always check the types.
Of course, like I said before, sometimes it's better to make it explicit what you want.
So if I was making a financial map, everything would be a double in the highest, what you call it
certainty.
That's not the word I'm looking for.
What's the word?
I'm looking for people.
The highest accuracy.
That's it.
Highest accuracy type of number.
Right.
So what's next?
Ah, here we go.
Now in iOS and Mac in general, every integer is actually referred to as a unit, which I think stands
for Universal Integer.
I could be wrong about that.
If we take a ONT eight that is actually stored in eight bytes, I believe, or eight bits, one of the
other, and if we look at the Macs and then press play on that.
The UNT max is two five five, so that can store from zero to two, five four or two, five five I believe.
I think it's two five five.
If you put a negative sign in front of it when you declare it, then you can store from like minus one
to seven to plus one to seven.
It's a bit of a weird one we will never use under eight.
OK, there is no need to do it in a modern application.
If you're making stuff on a microcontroller like an Arduino, then a untracked is your friend because
it uses much less memory.
Just make sure that you're never going to exceed the two five five four what you need it for.
Now, you can imagine there are all kinds of us, such as 16 dot Macs.
We have the U.S., 32 dot max and of course ont 64 dot Macs.
And if we play all of these, we'll see what their maximum values are.
So sixteen is sixty five thousand.
You may remember that if you had really old computers and if you're young and watching this, you won't
know this at all.
I'm guessing we used to have screens with sixteen bit color, which was amazing because you could have
65000 colors these days.
You can have millions of colors.
Right.
But that's the state of the art.
Back then.
We also before that had eight bit screens which had 255 colors.
So, you know, there's really old graphics, you see.
Well, that's the root of it.
It's stored an integer that was eight bits or bytes.
It's probably bits, but anyway.
32 bit stores that many numbers and 64 bit stores that many.
So if I was making a financial map, I would make sure I was running on a 64 bit system.
Every system these days is capable of 64 bit, but.
If you run on a 32 bit, that could potentially be a rounding error for a you integer or the bit where
it falls off the end and your whole program crashes.
OK, so you always got to bear in mind with variables, there are limits to what they can store, what
they can do and various other properties that they have.
OK, now, of course, we can define integers the explicit way.
So if I was going to do my num up top, I could say, hey, let's make this a U.
Int eight, because it actually fits in that.
But if I changed that to eight hundred, look what happens.
Integer, literal, eight hundred overflows.
So you've come to the very first error that you need to know about, which is called an overflow error.
It basically means you've gone out of range of what can actually be stored inside that variable.
You've heard of the website Stack Overflow.
That's based on two errors, the stack trace where you can trace through what went wrong and the overflow
which you've just seen.
Hence the name stack overflow.
Right.
Let's give you a little bit of homework, so let's copy this over.
And let's paste it straight in here.
Create an integer of any value in two ways, one explicitly typed and one implicitly typed.
Good luck.