Numbers


Numbers

The most basic element of math is the number. While this is probably not news to most people, it is important, especially in the world of programming, to realize that all numbers are not created equal. Mathematicians have many types of numbers: natural numbers , real numbers , complex numbers , prime numbers , and so forth. For our purposes, we really need only an understanding of integer , rational , and irrational numbers. While there are those of you who might someday need to gain an understanding of the intricacies of complex numbers, there are books out there twice the size of this tome dedicated to that subject alone. The majority of scripters will never need that level of knowledge, and therefore it is not included in this book.

Integers

The integer is perhaps the simplest of all numerical concepts in math, representing non- fractional numbers that are both positive and negative. For example, if we were to list every integer between “5 and 5, we would get “5, “4, “3, “2, “1, 0, 1, 2, 3, 4, and 5.

Rational Numbers

Rational numbers are numbers that can be represented as a fraction, and therefore are called fractional numbers. For example, 1/4 is a rational number. So is 0.25, and they are in fact the same number. An interesting realization is that every integer is also a rational number; for example, 8/2 = 4. The concept that one value can be two types of numbers is especially important to programming. Within a computer system, all rational numbers are stored as decimal numbers. That is, instead of storing a number as 3/4, it is stored as 0.75. If we were to multiply that by 10, we would get 7.5, or if we were to divide it by 10, we would get 0.075. The decimal point essentially floats among the numbers, giving us the programming term floating-point number. The other concept relating to rational, or floating-point numbers that a programmer has to realize is that of the limited precision of some of these numbers within the computer. Some fractions, like the ratio of a television screen 4/3, when solved produce an endless series of 3s as seen in Example 2.1.

Example 2.1: A repeating remainder of a rational number.

click to expand

Other rational numbers, while they might not produce an infinite repeating series of numbers, might produce a number so small that Maya cannot accurately represent it. While this floating-point precision does not generally cause a problem with the first representation of the number, when we use that number, possibly combined with other numbers that are also slightly less-than -accurate, we can receive a result that, while not technically incorrect, is not what we would have received if we had been more precise. In programming, we term this a floating-point error . These errors can add up over time and produce very noticeable discrepancies in the final result. Think of a photocopy. If we take a visual medium with high resolution, such as a black-and-white photo, and make a photocopy of it, the copy does not have nearly the quality of the original, but is still recognizable as the original photo. However, if we make a copy of the copy, and then a copy of the new copy, each resembles the original photograph less and less. If we repeat this process enough, we are eventually left with a completely unrecognizable mess. MEL uses 15 points of precision, which unless you are working at incredibly small scales or work with extraordinarily high tolerances, are more than enough for most uses of MEL.:

Irrational Numbers

The other type of number a MEL scripter often comes into contact with is the irrational number. Irrational numbers are those numbers which, to the best of human knowledge, never terminate, but are not a repeating remainder as in the case of 4/3. Perhaps the best known irrational number to artists is , which has been calculated out to millions of decimal places, with no noticeable pattern or end in sight. Pretty neat, if we consider that for a moment. While is the best known, there are others, such as . Because irrational numbers are also stored inside MEL as floating-point numbers, they also suffer from the same precision errors as the endlessly repeating rational numbers.




The MEL Companion
The MEL Companion: Maya Scripting for 3D Artists (Charles River Media Graphics)
ISBN: 1584502754
EAN: 2147483647
Year: 2003
Pages: 101

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net