Integers consist of any whole number either with a sign or without:
Perl allows you to add underscores to integers to make them easier for a human to read so for the last number in the list you can write:
This makes absolutely no difference to what the number is or how it is handled, it's just easier for our inferior mortal brains to comprehend.
There aren't really limits as to the highest and lowest integers that can be stored. The limits are basically subject to your computer's memory but I don't think in practise anyone really wants to use numbers that large. Also you will be sacrificing some precision when your numbers get that large and I think the reason for this is similar to why floating points are not entirely precise. Although I could be making that up.
So, on to floating points...
Floating points are numbers with a decimal point and also with or without a sign.
As with most programming languages, integers are (mostly) represented exactly but floating points are an approximation of what the decimal places are. It seems to me that this is because numbers are stored in binary and some fractions, for example a third, can only be expressed with an infinite binary representation. Seeing as computers do not have infinite memory, we have to chop off the end of the number and store the closest thing we have.
I think this level of precision is sufficient for most applications but I guess for research or anything scientific that requires precision, something else is going to be needed.
The 'e' in the middle of some of the numbers above mean that they are using the exponent. So 5.43e24 means 54.3 X 10^23 or 543 followed by 22 zeroes.
I always forget about these types of numbers, it makes me stop and remember that the only reason we count the way we do is because we have ten fingers and in a parallel world, eight-fingered martians are learning about this weird decimal way of counting.
I'm not really sure why anyone would use these in a real world application - maybe I'll see later on.
With non-decimal numbers, we have to indicate which type of numerical system we are using, otherwise they will just be treated as decimal numbers. The way to indicate these are really simple and not at all cumbersome:
0b1101110 - all binary numbers start with '0b'
0156 - all octal numbers start with a '0'
0x6e - all hex numbers start with '0x'
all the above amount to 110
These numbers can also be signed or unsigned.
Perl allows you to use operators on numbers so you can do calculations, these are the main ones:
/ division - this will always give you the floating point value if the result of the division is not an integer
% modulus - the values are always reduced to integers first, for example 10.5 % 3.2 will be calculated using 10 % 3 where the answer will be 1
** exponentiation - for example 2**3 means 2^3 or two to the power of three where the answer will be 8
So now we can do things like:
my $sum = 24 + 12;
my $subtraction = 10.5 - 5.3;
my $exponentiation = $sum**$subtraction;
As always, please add comments to this or any other of my posts. I'm a beginner so I need feedback on anything I've written that's wrong and also any extra information or helpful links or anything else you can think of that will help me learn is appreciated.