Web Assembly (Wasm) Numeric Types
Transcript from the "Numeric Types" Lesson
>> So, you're probably thinking, what do you mean numbers? There's one type of number, it's a number. And it's an integer. And those are positive or negative. Well, not really. An integer is a type of number. The two types of numbers we primarily care about in computing are floating point numbers, better numbers with a decimal place as in and the decimal can move, hence the floating point in moves, yeah.
[00:00:30] Yeah, you get it now, floating point yeah, it makes sense. And we have integers which are integers are whole numbers and they're either positive or negative. This is important because at the core of it, different numbers are represented differently in binary. So, a positive integer is going to have the leading bit of 0.
[00:00:51] And I'll use this example right here. So, this is the number 1. It is a, we'll say, it's assigned integer. So, when I say sign that means positive or negative. There's such thing as unsigned integers. And that's what a lot of times we're working in computer and engineering is unsigned integers.
[00:01:12] Think of unsigned integers as the absolute value of a number. So, it's not positive, it's not negative. It just is the number. And if you're thinking why do we need signs? Why we need a positive or negative? Why do we need to know that? The sign bit is always the leading bit.
[00:01:29] So, if this is a 1, that would make this number a negative 1, it's a zero so it's a positive. It's a positive zero. However, sometimes we want this bit of information to be as small and concise as possible. So, we use unsigned integer. And by using unsigned numbers, we get this extra bit of information back.
[00:02:15] It's so long. But there's a concept of the, it's called a max safe integer, because Java Script uses 64 bits to represent all of its numbers. It uses 64 bit floating point numbers and not integers. But if you're saying, if it's 64 bit, that means I should be able to do 2 to the 64th to get the largest number.
[00:02:55] If you've ever done heavy computations, or you're working with very, very large numbers, you actually want to use 64 bits of information. You wanna use as much information as possible, because that means we don't have to slice up that number into different parts and then perform computations on it.
[00:03:10] By having a 32-bit system versus a 64-bit system, a 64-bit system can represent larger numbers at once. And it can move those around much easier versus say, a 32-bit system which is gonna be constrained by only having 2 to the 32nd as the largest entry, 2 to 30, actually it's 2 to the 31 minus 1.
[00:03:56] You can use more of those numbers. It doesn't have to use to 253, you can use 2 to 61 or something like that. And again, the larger numbers we're using, the less computation and less number mangling we have to do, not super critical to know that's why I didn't really go too deep into it.
[00:04:13] But it's just interesting to know about the language we write, know and write every day. A lot of people don't know this. Actually, it turns out that 9 is 9 quadrillion, I'm trying to think it's 9 quadrillion grains of rice in the world? Sand on the beach. Hm, I don't know.
[00:05:29] And unfortunately it can't use 64 bit fully yet, it converts back and forth. It gets a little confusing. So, I try to stay away from the two confusing parts, but it means you can still do 64 bit math within WebAssembly itself, but when you export it, it's always gonna be a 32 bit pointer.
[00:05:50] So, it has to do that conversion for you.