Sunday, 21 August 2016
Floating Point
Floating point numbers have been a focus of computers for many years. Gaining floating point accuracy was the goal of many early computer scientists. Because there are an infinite possibilities of how many numbers can follow a decimal point, it’s impossible to truly represent any fraction completely using binary computing. A common example is π, which we call pi. It’s assumed that there are an endless number of digits fol- lowing 3.14. Even today computers are set loose to calculate the hundreds of billions of digits beyond the decimal point. Computers set aside some of the bits of a floating point number aside to represent where the decimal appears in the number, but even this is limited. The first bit is usually the sign bit, setting the negative or positive range of the number. The following 8 bits is the exponent for the number called a mantissa. The remaining bits are the rest of the number appearing around the decimal point. A float value can move the decimal 38 digits in either direction, but it’s limited to the values it’s able to store. We will go further into how numbers are actually stored in terms of 1s and 0s in Section 8.9. For now just understand that numbers can represent only a limited number of digits. Without special consider- ations, computers are not able to handle arbitrarily large numbers. To cast a float into an int, you need to be more explicit. That’s why C# requires you to use the cast and you need to add the (int) in int Zint = (int)Zmove;. The (int) is a cast operator; or rather (type) acts as a converter from the type on the right to the type needed on the left.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment