Computer Arithmetic and the Mathcw Library

Computer Arithmetic and the Mathcw Library

Computer arithmetic and the MathCW library Nelson H. F. Beebe Research Professor University of Utah Department of Mathematics, 110 LCB 155 S 1400 E RM 233 Salt Lake City, UT 84112-0090 USA Email: [email protected], [email protected], [email protected] (Internet) WWW URL: http://www.math.utah.edu/~beebe Telephone: +1 801 581 5254 FAX: +1 801 581 4148 13 December 2008 Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 1 / 1 Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 2 / 1 Common misconceptions about computer arithmetic J Integer arithmetic is always exact J Integer overflows are caught J Floating-point arithmetic is fuzzy J Floating-point equality comparisons are unreliable J Floating-point precision and range are adequate for everyone J Rounding errors accumulate J Computers execute arithmetic code in the order and precision in which it is written J Underflows are harmless J Overflows are disastrous J Sign of zero does not matter J Arithmetic exceptions should cause job termination Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 3 / 1 Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 4 / 1 Infamous disasters in computer arithmetic Arithmetic and democratic elections J USS Yorktown nuclear-weapons carrier dead in water in 1997 for three hours after integer overflow in spreadsheet shut down software control (potential cost: loss of a war) J German state election in Schleswig–Holstein reversed in 1992 because J US Patriot missiles fail to shoot down Iraqi Scuds in 1990 Gulf War of rounding errors in party vote percentages due to timer counter integer overflow J The US presidential elections in 2000 and 2004, the State of J European Space Agency Ariane 5 missile loss offWest Africa in 1996 Washington gubernatorial election in 2004, and the Mexico due to arithmetic overflow in floating-point to integer conversion in presidential election in 2007, were so close that even minor errors in guidance system (cost US$1B) counting could have changed the results ≈ J Too few digits in US National Debt Clock (9-Oct-2008), US gas J Some US electronic voting machines in 2004 were found to have pumps, and Y2K fiasco (US$600B – US$1000B) counted backwards, subtracting votes, either because of counter J Intel Pentium floating-point divide flaw in 1994 (US$400M – overflow and wraparound, or malicious tampering with the software. US$600M) J New York and Vancouver Stock Exchange shutdowns (cost: n × US$10M) Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 5 / 1 Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 6 / 1 Historical floating-point arithmetic Historical flaws on some systems J Konrad Zuse’s Z1, Z3, and Z4 (1936–1945): 22-bit (Z1 and Z3) and Floating-point arithmetic can make error analysis difficult, with behavior 63 19 like this in some older designs: 32-bit Z4 with exponent range of 2± 10± ≈ J Burks, Goldstine, and von Neumann (1946) argued against J u 1.0 u 6= × floating-point arithmetic J u u 2.0 u + 6= × J It is difficult today to appreciate that probably the biggest problem J u 0.5 u/2.0 facing programmers in the early 1950s was scaling numbers so as to × 6= J u v but u v 0.0, and 1.0/(u v) raises a zero-divide error achieve acceptable precision from a fixed-point machine, Martin 6= − = − J u 0.0 but 1.0/u raises a zero-divide error Campbell-Kelly (1980) 6= J u v v u J IBM mainframes from mid-1950s supplied floating-point arithmetic × 6= × J underflow wraps to overflow, and vice versa J IEEE 754 Standard (1985) proposed a new design for binary floating-point arithmetic that has since been widely adopted J division replaced by reciprocal approximation and multiply J IEEE 754 design first implemented in Intel 8087 coprocessor (1980) J poor rounding practices increase cumulative rounding error Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 7 / 1 Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 8 / 1 IEEE 754 binary floating-point arithmetic IEEE 754 binary floating-point arithmetic s exp significand J NaN from 0/0, , f (NaN), x op NaN,... bit 0 1 9 31 single ∞−∞ J NaN NaN is distinguishing property, but botched by 10% of 0 1 12 63 double 6= 0 1 16 79 extended compilers 0 1 16 127 quadruple J from big/small, including nonzero/zero ±∞ 0 1 22 255 octuple J precisions in bits: 24, 53, 64, 113, 235 J approximate precisions in decimal digits: 7, 15, 19, 34, 70 J s is sign bit (0 for ,1for ) + − J approximate ranges (powers of 10): [ 45,38], [ 324,308], J exp is unsigned biased exponent field − − [ 4951,4932], [4966,4932], [ 315723,315652] J smallest exponent: zero and subnormals (formerly, denormalized) − − J largest exponent: Infinity and NaN (Not a Number) J significand has implicit leading 1-bit in all but 80-bit format J 0, , signaling and quiet NaN ± ±∞ Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 9 / 1 Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 10 / 1 IEEE 754 binary floating-point arithmetic Why the base matters J nonstop computing model J accuracy and run-time cost of conversion between internal and J five sticky flags record exceptions: underflow, overflow, zero divide, external (usually decimal) bases invalid, and inexact J effective precision varies when the floating-point representation uses a J four rounding modes: to-nearest-with-ties-to-even (default), radix larger than 2 or 10 to-plus-infinity, to-minus-infinity, and to-zero J reducing the exponent width makes digits available for increased J traps versus exceptions precision J J fixups in trap handlers impossible on heavily-pipelined or parallel for a fixed number of exponent digits, larger bases provide a wider architectures (since IBM System/360 Model 91 in 1968) exponent range, and reduce incidence of rounding J J no language support for advanced features until 1999 ISO C Standard for a fixed storage size, granularity (the spacing between successive representable numbers) increases as the base increases J some architectures implement only subsets (e.g., no subnormals, or J only one rounding mode, or only one kind of NaN, or in embedded in the absence of underflow and overflow, multiplication by a power of systems, neither Infinity nor NaN) the base is an exact operation, and this feature is essential for many computations, in particular, for accurate elementary and special J some platforms have nonconforming rounding behavior functions Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 11 / 1 Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 12 / 1 Base conversion problem Decimal floating-point arithmetic J Absent in most computers from mid-1960s to 2007 J IBM Rexx and NetRexx scripting languages supply decimal arithmetic J exact in one base may be inexact in others (e.g., decimal 0.9is with arbitrary precision (109 digits) and huge exponent range 999999999 hexadecimal 0x1.cccccccccccccccccccccccc...p-1) (10± ) J 5% sales-tax example: binary arithmetic: 0.70 1.05 0.734999999..., J IBM library provides portable decimal arithmetic, and × = decNumber which rounds to 0.73; correct decimal result 0.735 may round to 0.74 leads to hardware designs in IBM zSeries (2006) and PowerPC (2007) J Goldberg (1967) and Matula (1968) showed how many digits needed J GNU compilers implement low-level support in late 2006 for exact round-trip conversion J business processing traditionally require 18D fixed-point decimal, but J exact conversion may require many digits: more than 11500 decimal COBOL 2003 mandates 32D, and requires floating-point as well digits for binary-to-decimal conversion of 128-bit format, J four additional rounding modes for legal/tax/financial requirements J base-conversion problem not properly solved until 1990s J integer, rather than fractional, coefficient means redundant J few (if any) languages guarantee accurate base conversion representation, but allows emulating fixed-point arithmetic J quantization primitives can distinguish between 1, 1.0, 1.00, 1.000, etc. J trailing zeros significant: they change quantization Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 13 / 1 Nelson H. F. Beebe (University of Utah)Computer arithmetic & the MathCW library 13 December 2008 14 / 1 Decimal floating-point arithmetic Library problem s cf ec cc J Need much more than ADD, SUB, MUL, and DIV operations J mathcw library provides full C99 repertoire, including printf and bit 0 1 6 9 31 single scanf families, plus hundreds more [but not functions of type 0 1 6 12 63 double complex] 0 1 6 16 127 quadruple J code is portable across all current platforms, and several historical 0 1 6 22 255 octuple ones (PDP-10, VAX, S/360, . ) J IBM Densely-Packed Decimal (DPD) and Intel Binary-Integer Decimal J supports six binary and four decimal floating-point datatypes (BID) in 32-bit, 64-bit, 128-bit, and 256-bit formats provide 3n 1 + J separate algorithms cater to base variations: 2, 8, 10, and 16 digits: 7, 16, 34, and 70 J J wider exponent ranges in decimal than binary: [ 101,97], [ 398,385], pair-precision functions for even higher precision − − [ 6176,6145], and [ 1572863,1572865] J fused multiply-add (FMA) via pair-precision arithmetic − − J cf (combination field), ec (exponent continuation field), (cc) J programming languages: Ada, C, C++, C#, Fortran, Java, Pascal (coefficient combination field) J scripting languages: gawk, hoc, lua, mawk, nawk J Infinity and NaN recognizable from first byte (not true in binary formats) Nelson H.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us