classes of real numbers all real numbers can be
play

Classes of Real Numbers All real numbers can be represented by a - PDF document

Classes of Real Numbers All real numbers can be represented by a line: 1/2 1 0 1 2 3 4 The Real Line integers rational numbers real numbers non-integral fractions irrational numbers


  1. Classes of Real Numbers All real numbers can be represented by a line: 1/2 π ✛ ✲ − 1 0 1 2 3 4 The Real Line  � integers rational numbers   real numbers non-integral fractions  irrational numbers  Rational numbers All of the real numbers which consist of a ratio of two integers. Irrational numbers Most real numbers are not rational, i.e. there is no way of writing them as the ratio of two integers. These numbers are called irrational . √ Familiar examples of irrational numbers are: 2, π and e . How to represent numbers? • The decimal , or base 10 , system requires 10 symbols, 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9. • The binary , or base 2 , system is convenient for electronic computers: here, every number is represented as a string of 0 ’s and 1 ’s. Decimal and binary representation of integers is simple, requiring an expansion in nonnegative powers of the base; e.g. (71) 10 = 7 × 10 + 1 and its binary equivalent: (1000111) 2 = 1 × 64 + 0 × 32 + 0 × 16 + 0 × 8 + 1 × 4 + 1 × 2 + 1 × 1 . Non-integral fractions have entries to the right of the point. e.g. finite representations 11 2 = (5 . 5) 10 = 5 × 1 + 5 × 1 10 , 11 2 = (101 . 1) 2 = 1 × 4 + 0 × 2 + 1 × 1 + 1 × 1 2 1

  2. Infinitely Long Representations But 1 / 10, with finite decimal expansion (0 . 1) 10 , has the binary representation 1 = (0 . 0001100110011 . . . ) 2 10 16 + 1 1 32 + 0 0 1 1 = 64 + 128 + 256 + 512 + · · · . This, while infinite , is repeating . 1 / 3 has both representations infinite and repeating: 1 / 3 = (0 . 333 . . . ) 10 = (0 . 010101 . . . ) 2 . If the representation of a rational number is infinite , it must be repeating . e.g. 1 / 7 = (0 . 142857142857 . . . ) 10 . Irrational numbers always have infinite, non-repeating expansions. e.g. √ 2 = (1 . 414213 ... ) 10 , π = (3 . 141592 . . . ) 10 , e = (2 . 71828182845 . . . ) 10 . Converting between binary & decimal. • Binary − → decimal : Easy. e.g. (1001 . 11) 2 is the decimal number 1 × 2 3 + 0 × 2 2 + 0 × 2 1 + 1 × 2 0 + 1 × 2 − 1 + 1 × 2 − 2 = 9 . 75 • Decimal − → binary : Convert the integer and fractional parts separately. e.g. if x is a decimal integer , we want coefficients a 0 , a 1 , . . . , a n , all 0 or 1, so that a n × 2 n + a n − 1 × 2 n − 1 + · · · + a 0 × 2 0 = x, has representations ( a n a n − 1 · · · a 0 ) 2 = ( x ) 10 . Clearly dividing x by 2 gives remainder a 0 , leaving as quotient a n × 2 n − 1 + a n − 1 × 2 n − 2 + · · · + a 1 × 2 0 , and so we can continue to find a 1 then a 2 etc. Q: What is a similar approach for decimal fractions? 2

  3. Computer Representation of Numbers • Integers — three ways: 1. sign-and-modulus — a simple approach. Use 1 bit to represent the sign , and store the binary representation of the magnitude of the integer. e.g. decimal 71 is stored as the bitstring 0 00. . . 01000111 If the computer word size is 32 bits, 2 31 − 1 is the largest magnitude which will fit. 2. 2’s complement representation (CR) more convenient, & used by most machines. (i) The nonnegative integers 0 to 2 31 − 1 are stored as before, e.g., 71 is stored as the bitstring 000. . . 01000111 (ii) A negative integer − x , where 1 ≤ x ≤ 2 31 , is stored as the positive integer 2 32 − x . e.g. − 71 is stored as the bitstring 111. . . 10111001 . Converting x to its 2’s CR 2 32 − x of − x : 2 32 − x = (2 32 − 1 − x ) + 1 , 2 32 − 1 = (111 . . . 111) 2 . Chang all zero bits of x to ones, one bits to zero and adding one . Q: What is the quickest way of deciding if a number is negative or nonnegative using 2’s CR ?? An advantage of 2’s CR: Form y + ( − x ), where 0 ≤ x, y ≤ 2 31 − 1. 2’s CR of − x is 2 32 − x 2’s CR of y is y ; Adding these two representations gives y + (2 32 − x ) = 2 32 + y − x = 2 32 − ( x − y ) . 3

  4. – If y ≥ x , the LHS will not fit in a 32-bit word, and the leading bit can be dropped, giving the correct result , y − x . – If y < x , the RHS is already correct , since it represents − ( x − y ). Thus, no special hardware is needed for integer subtraction . The addition hardware can be used, once − x has been represented using 2’s complement. 3. 1’s complement representation: a negative integer − x is stored as 2 32 − x − 1. This system was used, but no longer. • Non-integral real numbers. Real numbers are approximately stored using the binary representation of the number. Two possible methods: . fixed point and floating point . Fixed point: the computer word is divided into three fields , one for each of: • the sign of the number • the number before the point • the number after the point. In a 32-bit word with field widths of 1,15 and 16 , the number 11 / 2 would be stored as: 0 000000000000101 1000000000000000 The fixed point system has a severe limitation on the size of the numbers to be stored. e.g. Q: smallest to largest magnitudes above? Inadequate for most scientific computing . Normalized Exponential Notation In (normalized) exponential notation , a nonzero real number is written as ± m × 10 E , 1 ≤ m < 10 , • m is called the significand or mantissa, • E is an integer , called the exponent . 4

  5. For the computer we need binary , write x � = 0 as x = ± m × 2 E , where 1 ≤ m < 2 . The binary expansion for m is m = ( b 0 .b 1 b 2 b 3 . . . ) 2 , with b 0 = 1 . IEEE Floating Point Representation Through the efforts of W. Kahan & others, a binary floating point standard was developed: IEEE 754-1985. It has now been adopted by almost all computer manufacturers. Another standard, IEEE 854-1987 for radix independent floating point arithmetic, is devoted to both binary (radix-2) and decimal (radix- 10) arithmetic. The current version is IEEE 754-2008, including nearly all of the original IEEE 754-1985 and IEEE 854-1987 ✞ ☎ We write IEEE FPS for the binary standard. ✝ ✆ Three important requirements: • consistent representation of floating point numbers across machines • correctly rounded arithmetic • consistent and sensible treatment of exceptional situations (e.g. division by 0). IEEE Single format There are 3 standard types in IEEE FPS: single , double , and extended format. Single format numbers use 32-bit words . A 32-bit word is divided into 3 fields : • sign field : 1 bit ( 0 for positive, 1 for negative). • exponent field : 8 bits for E . • significand field : 23 bits for m . In the IEEE single format system , the 23 significand bits are used to store b 1 b 2 . . . b 23 . Do not store b 0 , since we know b 0 = 1. This idea is called hidden bit normalization . The stored bitstring b 1 b 2 . . . b 23 is now the fractional part of the significand, the significand field is also referred to as the fraction field . It may not be possible to store x with such a scheme, because 5

  6. • either E is outside the permissible range (see later). • or b 24 , b 25 , . . . are not all zero . Def. A number is called a (computer) floating point number if it can be stored exactly this way. e.g 71 = (1 . 000111) 2 × 2 6 can be represented by 0 E = 6 0001110000000000000000 . If x is not a floating point number, it must be rounded before it can be stored on the computer. Special Numbers • 0 . Zero cannot be normalized . A pattern of all 0s in the fraction field of a normalized number represents the significand 1.0 , not 0.0 . • − 0. − 0 and 0 are two different representations for the same value • ∞ . This allows e.g. 1 . 0 / 0 . 0 → ∞ , instead of terminating with an overflow message. • −∞ . −∞ and ∞ represent two very different numbers . • NaN, or “Not a Number” , and is an error pattern . • Subnormal numbers (see later) All special numbers are represented by a special bit pattern in the exponent field . Precision, Machine Epsilon Def. Precision : The number of bits in the significand (including the hidden bit) is called the precision of the floating point system, denoted by p . In the single format system, p = 24. Def. Machine Epsilon : The gap between the number 1 and the next larger floating point number is called the machine epsilon of the floating point system, denoted by ǫ . In the single format system, the number after 1 is b 0 .b 1 . . . b 23 = 1 . 00000000000000000000001 , ǫ = 2 − 23 . so 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend