11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

338 numeric dataselect customer where (today - customer.lastpurchasedate) > 30Programming packages such as Mathematica are alsononprocedural in that they allow for problems to be statedusing the same symbolic notation that mathematiciansemploy, <strong>and</strong> many st<strong>and</strong>ard procedures for solving or transformingequations are then carried out automatically.Other examples <strong>of</strong> relatively nonprocedural languagesinclude logic-programming languages (see Prolog <strong>and</strong>expert systems) <strong>and</strong> languages where the desired resultsare built up from defining functions rather than through aseries <strong>of</strong> procedural steps (see lisp <strong>and</strong> functional languages).Further ReadingAbraham, Paul W., et al. Functional, Concurrent <strong>and</strong> Logic ProgrammingLanguages. Vol. 4 <strong>of</strong> H<strong>and</strong>book <strong>of</strong> Programming Languages,edited by Peter H. Salus. Indianapolis: MacmillanTechnical Publishing, 1998.Gilmore, Stephen, ed. Trends in Functional Programming. Portl<strong>and</strong>,Ore.: Intellect, 2005.Truitt, Thomas D., Stuart B. Mindlin, <strong>and</strong> Tarralyn A. Truitt. AnIntroduction to Nonprocedural Languages: Using NPL. NewYork: McGraw-Hill, 1983.numeric dataText characters <strong>and</strong> strings can be stored rather simply incomputer memory, such as by devoting 8 bits (one byte) or16 bits to each character. The storage <strong>of</strong> numbers is morecomplex because there are both different formats <strong>and</strong> differentsizes <strong>of</strong> numbers recognized by most programminglanguages.Integers (whole numbers) have the simplest representation,but there are two important considerations: the totalnumber <strong>of</strong> bits available <strong>and</strong> whether one bit is used to holdthe sign.Since all numbers are stored as binary digits, an unsignedinteger has a range from 0 to 2 bits where “bits” is the totalnumber <strong>of</strong> bits available. Thus if there are 16 bits available,the maximum value for an integer is 65535. If negativenumbers are to be h<strong>and</strong>led, a signed integer must be used(in most languages such as C, C++, <strong>and</strong> Java, an integer issigned unless unsigned is specified). Since one bit is usedto hold the sign <strong>and</strong> each bit doubles the maximum size, itfollows that a signed integer can have only half the rangeabove or below zero. Thus, a 16-bit signed integer can rangefrom -32,768 to 32,767.One complication is that the available sizes <strong>of</strong> integersdepend on whether the computer system’s native data sizeis 16, 32, or 64 bits. In most cases the native size is 32 bits,so the declaration “int” in a C program on such a machineimplies a signed 32-bit integer that can range from - 2 31 or-2,147,483,647 to 2 31 -1, or 2,147,483,647. However, if one isusing large numbers in a program, it is important to checkthat the chosen type is large enough. The long specifier is<strong>of</strong>ten used to indicate an integer twice the normal size, or64 bits in this case.Floating Point NumbersNumbers with a fractional (decimal) part are usually storedin a format called floating point. The “floating” means thatthe location <strong>of</strong> the decimal point can be moved as necessaryto fit the number within the specified digit range. A floatingpoint number is actually stored in four separate parts. Firstcomes the sign, indicating whether the number is negativeor positive. Next comes the mantissa, which contains theactual digits <strong>of</strong> the number, both before <strong>and</strong> after the decimalpoint. The radix is the “base” for the number systemused. Finally, the exponent determines where the decimalpoint will be placed.For example, the base 10 number 247.35 could be representedas 24735 × 10 -2 . The -2 moves the decimal pointat the end two places to the left. However, floating-pointnumbers are normalized to a form in which there is just onedigit to the left <strong>of</strong> the decimal point. Thus, 247.35 wouldactually be written 2.4735 × 10 2 . This system is also knownas scientific notation.As noted earlier, actual data storage in modern computersis always in binary, but the same principle applies.According to IEEE St<strong>and</strong>ard 754, 32-bit floating-point numbersuse 1 bit for the sign, 8 bits for the exponent, <strong>and</strong> 23bits for the mantissa (also called the signific<strong>and</strong>, since itexpressed the digits that are significant—that is, guaranteednot to be “lost” through overflow or underflow in processing).The double precision float, declared as a “double”in C programs, uses 1, 11, <strong>and</strong> 52 bits respectively.Programmers who use relatively small numbers (such ascurrency amounts) generally don’t need to worry about loss<strong>of</strong> precision. However, if two numbers being multiplied arelarge enough, even though both numbers fit within the 32-bit size, their product may well generate more digits thancan be held within the 23 bits available for the mantissa.This means that some precision will be lost. This can beavoided to some extent by using the “double” size.Since floating-point calculations use more processorcycles (see microprocessor) than integer calculations,processor designers have paid particular attention toimproving floating-point performance. Indeed, processorsare <strong>of</strong>ten rated in terms <strong>of</strong> “megaflops” (millions <strong>of</strong> floatingpointoperations per second) or even “gigaflops” (billions <strong>of</strong>flops).Further Reading“IEEE St<strong>and</strong>ard for Floating Point Arithmetic.” Available online.URL: http://www.psc.edu/general/s<strong>of</strong>tware/packages/ieee/ieee.html. Accessed August 16, 2007.“Numeric Data Types <strong>and</strong> Expression Evaluation [in C].” Availableonline. URL: http://www.psc.edu/general/s<strong>of</strong>tware/packages/ieee/ieee.html. Accessed August 16, 2007.Sebesta, Robert W. Concepts <strong>of</strong> Programming Languages. 8th ed.Boston: Addison-Wesley, 2007.“Type Conversion <strong>and</strong> Conversion Operators in C#.” Availableonline. URL: http://www.psc.edu/general/s<strong>of</strong>tware/packages/ieee/ieee.html. Accessed August 16, 2007.“xmL Schema Numeric Data Types.” Available online. URL: http://www.psc.edu/general/s<strong>of</strong>tware/packages/ieee/ieee.html.Accessed August 16, 2007.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!