High-Precision C++ Arithmetic

Size: px
Start display at page:

Transcription

1 Base One International Corporation 44 East 12th Street New York, NY High-Precision C++ Arithmetic - Base One s Number Class fixes the loopholes in C++ high-precision arithmetic Base One's Number Class is a general-purpose alternative to the built-in numeric data types of C++, with added safeguards against a variety of common (and not-so-common) errors. The Base/1 Number Class is built on an innovative technology for performing highly precise mathematical calculations. (U.S. Patent Number 6,384,748) The Number Class lets programmers eliminate unacceptable rounding errors and destructive, high-order truncation. Programmers can easily replace numeric datatype declarations (double, int, unsigned long, etc.) and gain efficient, high-precision arithmetic on numbers and fractions with up to 100 decimal digits. While C++ has become the tool of choice for building all types of applications, it still suffers from limitations that can be traced to its roots as a scientific programming language for minicomputers. For example, C++ lacks features supporting high-precision decimal arithmetic, which have long existed on mainframe computers because of their orientation toward large-scale business applications. Although C/C++'s native numeric data types work fine in many situations, their underlying binary representation and limited precision present problems that become more apparent as the number of significant digits increases. Thus, for example, native C++ numbers lose accuracy because of rounding, or worse, results can be grossly in error because of failure to detect the truncation of high-order digits in a calculation that produces an overflow. While these shortcomings of C/C++ can be overcome with extra programming effort, one must be diligent, and it's easy to make subtle mistakes that don't show up for years. But the beauty of C++ is that it allows you to solve a problem once and reuse that solution from then on. Programmers can make use of Base One s Number Class just as easily as the native C++ number types. Existing applications are easy to convert. With a few localized changes to include the required header files, huge applications can be made to support greatly enhanced precision simply by recompiling. Because it addresses such a fundamental and general language feature, the Base/1 Number Class applies to a wide range of application types: financial applications: e.g. banking, securities, insurance, and accounting applied mathematics: engineering, physical sciences, etc. pure mathematics and computer science 1

2 Advantages Over C++ Built-In Numeric Types The Number Class provides numbers that can have guaranteed precision, i.e. length or number of significant figures. Internally, the Number Class uses algorithms have some similarities to BCD (Binary Coded Decimal) to do its arithmetic, and a number is stored as a compacted, variable length string. Externally, the Number Class behaves like a floating point number, except that it's better behaved. There's no pervasive, destructive rounding going on. Arithmetic is done exactly. The Number Class efficiently supports numbers that are much larger than can be held by any C++ numeric data type. The Number Class is designed to hold positive and negative numbers ranging from the very small, 1 x 10**-99, to the very large, x 10**99. The maximum precision supported is 100 (length) and a maximum scale of

3 The Number Class uses a variable-length representation that allows numbers to be manipulated as raw null-terminated character strings, which are supported very efficiently in C++. In performing the encoding, the first step always is to canonicalize the number into an equivalent form that has a mantissa with a single non-zero digit to the the left of the decimal point. Digits are then processed in a pairwise fashion to pack them into each byte, with the addition of a single trailing zero if needed to fill the last byte. Sign reversals are performed in such a way as to guarantee the collatability of signed numbers and fractions. Finally, a bias of plus or minus 10 adjusts the byte values to assure that a null byte can never occur in either the exponent or the mantissa. Decimal floating point representation avoids repeating binary fractions: It is commonly known that some simple fractions, like 1/3, can not be exactly represented in decimal notation. Depending on the choice of base, there will always be certain fractions that can only be represented by an infinitely repeating series of digits to the right of the decimal point. Because C++ number types use an underlying binary representation, most decimal fractions have no exact representation as standard C++ floating point numbers. For example even the simple decimal number 0.1 (one tenth) translates into the repeating binary fraction, , ad infinitum. This means that C++ floating point is incapable of exactly representing most decimal fractions, regardless of the choice of precision. On the other hand, the Number Class uses a compact decimal encoding, so it can exactly represent any decimal fraction up to 100 digits of precision. Since people are accustomed to dealing with decimal numbers, this is the form in which numbers usually originate, and also the form in which results are reported. Financial applications are a classic example of the need for exact decimal arithmetic, because large accounts may be required to balance right down to the penny. By using the Number Class, you eliminate the fundamental inaccuracy of C++'s binary number types. 3

4 Much higher precision limits: The most important general determinant of accuracy is the number of significant digits a number can represent, regardless of whether a binary or decimal encoding is used. For C++ numbers on a PC, the limit comes down to a 64 bit maximum that standard C++ number types can occupy. This translates into a maximum of 19 significant decimal digits for fixed point C++ numbers, or about 16 significant digits for floating point. (Remember, the C language evolved from minicomputers.) The Number Class supports up to 100 significant decimal digits, so it can be vastly more accurate than any C++ number. This makes our Number Class a great tool for scientific and mathematical applications that demand extreme precision. Number Class uses a fixed scale instead of a floating decimal point: Scientific applications can be satisfied with a floating decimal point, so long as a fixed precision can be guaranteed. This is NOT a sufficient form of precision for business and database applications. If the decimal point is allowed to float, then, for example, you can't depend on the accuracy to a particular number of digits to the right of the decimal point. In other words, "accurate to the penny" means knowing that no operation caused the value to the right of the decimal point to be lost through rounding. For this reason Number Class uses a fixed scale that can satisfy both business and scientific applications. Space-efficient variable length encoding stores only the actual digits required: On a PC, for example, C++ supports native fixed and floating point numeric types that occupy up to 8 bytes (64 bits). Floating point is able to represent a much wider range from tiny fractions to very large numbers, but the tradeoff is a reduction in precision. In either case, C++ numbers use a fixed-length encoding, so that a variable of a declared number type will always be the same size, which must be large enough to hold the largest possible value this type can represent. The Number Class, however, is a variable-length numeric encoding built upon standard C++ nullterminated string classes. Only the amount of space actually needed to hold the current value is allocated. A single null byte is all that is required to store the NULL value, and a simple decimal number can be stored in as little as two bytes, while a number with as many as 100 significant decimal digits can be stored in another variable, yet these are both instances of the same ubiquitous Number Class type. For a typical distribution of decimal number values in a real application, the Number Class' variable length can yield dramatic reductions in the consumption of both memory and disk storage. The Number Class allocates and stores only the digits that are required to exactly represent the particular value it holds, without needless padding. When there is a mix of long and short numbers, as is typical in many applications, use of Base One's Number Class substantially reduces memory and disk space requirements. 4

5 No matter how may digits of precision you sometimes need, the number is stored in the minimum amount of space that the specific number requires. Null (blank) numbers require one byte. Zero requires 2 bytes. A non-zero, non-null number always requires at least 4 bytes. One or two digits needs 4 bytes; 3 or 4 digits, 5 bytes; 5 or 6 digits, 6 bytes, etc.. The formula is: (3 + ((NumDigits + 1) / 2)) with the division performed being an INTEGER division (i.e. rounded down). (No extra space is required to store either the number's length or its decimal point in the Number Class.) As the precision (length) of numbers is increased, the fixed overhead of the sign, exponent, and terminator bytes diminishes in importance, and the size approaches 2 decimal digits per byte. Note that this format does NOT need to store zeroes on the left and right of the decimal point. That is, 4.2 and and all require 4 bytes to store. (This is not the case in packed decimal, for example, because significant zero is treated like any other digit.) The Number Class not only avoids needless padding with leading and trailing zeroes (in numbers like and ), but it also has a unique ability to compress significant zeroes (as in and ). Thus, Number Class shares the advantage of floating point's compact representation of very large and very small numbers, but without the drawback of floating point's limited accuracy. Database Connectivity If you build database applications, the Base/1 Number Class provides additional benefits whether you use a standard relational database management system (RDBMS), an objectoriented database, ISAM, or flat files to store your data. Besides its general compactness and speed, the Number Class addresses the following issues of importance to designers of information storage and retrieval systems: Modern databases can store numbers that are longer than C++ can manipulate: For example, Oracle can support a 38-digit numeric field, but there is no C++ data type that can exactly represent or perform arithmetic against such numbers. The Number Class can handle numbers of far greater length and precision than those supported by any major DBMS. C++ numeric data types don't support the concept of a null number, distinct from zero: In database applications, it can be useful to have a way of leaving a numeric field blank, meaning that data is not available, but the value is not necessarily zero. The ANSI SQL database standard has long provided for NULL values, but this notion is foreign to the C++ programming language. However, the Number Class does support null numbers, as distinct from numbers with a value of zero, so it handles this widely accepted database feature. 5

6 Conventional number representations are not amenable to efficient indexing: Indexing is essential to good performance in large database applications, because it greatly speeds up searching and obtaining filtered, sorted query results. Unfortunately most numeric representations were designed for arithmetic, not for indexing. Consequently, extra logic is needed to transform numbers into keys in a format that collates properly. None of this logic is handled automatically by C++, so it usually falls upon the DBMS or the application programmer to perform the additional processing. The Number Class is markedly different from conventional fixed or floating point binary numbers, which are inherently limited in their ability to represent exact decimal fractions. While resembling the "packed decimal" of mainframe computers, the Number Class uses a radically different encoding scheme to support much more efficient arithmetic and comparison algorithms. A unique benefit of Base One's encoding is that it makes numbers directly collatable as variablelength byte strings, regardless of the mix of numeric sign, scale, or precision. This makes the Number Class exceptionally well-suited to searching, sorting, and indexing applications. The following table illustrates how Number Class values collate directly into proper numerical sequence, as conventional C signed character arrays. Unlike other numeric representations, the Number Class handles variable sign, precision, and scale, as well as a "Null" value with no need for conversion into a different representation for efficient sorting and indexing. Notice how the 10 sample numbers in the table collate correctly, from smallest to largest (null, , -12.3, , , 0, , 0.439, 1.234, and finally ). Collatability of Internal Representation Internal Representation Number as a Null-Terminated String (Byte Array Values) (Null) 'n' 'n' 'n' 'n' 'o' 'p' 'p' 'p' 'p' The Number Class has a special internal string format that orders numbers properly under the rules of standard byte string comparison. In other words, first come blanks, then negative numbers, then zero, and finally progressively increasing positive numbers. No transformation is necessary for Number Class fields, because they are already in a representation that collates conveniently, making indexing extremely easy and efficient. Furthermore, the Number Class 6

7 allows compound keys to be formed simply by concatenating multiple fields, even if they are of mixed character and numeric types. No other numeric representation has these characteristics. For users of BFC (Base/1 Foundation Component Library), a further advantage of the Number Class is its total integration with the Database Library s data dictionary and database retrieval and modification operations. Numbers can be stored into and retrieved from database records directly using Number Class variables. In addition, Number Class instances can be initialized to the attributes of a database field defined in the data dictionary, including length (precision), scale, and a formatting mask to be used for display and/or data entry. For example, if you know that a calculated value will end up being stored in a particular field, initializing the number with that field's name will automatically insure that its length and scale will be the basis for proper rounding behavior and for generating overflow error notification when appropriate limits have been exceeded. (These are smart numbers!) Comprehensive Error Handling Even if your application doesn't require the highest level of precision, Base One's Number Class makes it easier to write reliable applications by adding convenient error-trapping features. This covers errors like Overflow, Divide by zero, Invalid sign, etc., which are not handled automatically by C++. C++ provides only minimal facilities for detecting and handling errors that can occur in numeric arithmetic and conversion operations. This makes it necessary for programmers to take extra steps to be sure that certain errors, such as division by zero and overflow, cannot occur. Otherwise, a program may crash or simply yield incorrect results when one of these exceptional conditions arises. All too often obscure bugs result from failing to add adequate error checking logic. The Number Class provides additional capabilities for detecting and handling errors, so these details don't burden the programmer but they also don't get overlooked: The Number Class supports dynamic conversion between datatypes without requiring explicit casting. An error is thrown if an illegal conversion is attempted, for example a very large long value being assigned to a short int or a negative number to an unsigned. Exceptions are thrown whenever a significant truncation would take place or the number cannot sustain the required number of digits to the right of the decimal point without corrupting the number (e.g. ERR_OverflowNum, ERR_DivideByZero). 7

8 Convenient Overflow/Underflow Behavior: If you add two conventional C++ numbers and the correct result requires more digits than the variable can hold, C++ doesn't detect the error, as you might have expected if you were accustomed to programming on old mainframe computers. Instead, C++ simply wraps the value, effectively truncating the most significant digits and producing totally incorrect results without any notification. Base One's Number Class gives you an easy way to trap and handle these errors, without having to write extra code to explicitly check for overflow on each arithmetic operation. The behavior of Number Class arithmetic is analogous to arithmetic with native C++ datatypes with one useful difference. The Number Class throws an exception when destructive overflow errors occur. For example in C++ if two short variables having +30,000 each are added, the result is not 60,000 and NO overflow error is reported. Similarly, if two short variables have -30,000 each and are added, the result would be incorrect and NO destructive "underflow" error would be reported. On the other hand, those same operations done with Number Class objects would result in exceptions being thrown that indicate the overflow error. The Number Class throws these exceptions only if the number of digits on the left hand side of the decimal point of the result is too large to be held. If the number of digits on the right hand side of the decimal point is too large then it gets rounded according to the required scale. When the result of arithmetic gets assigned to a Number Class object, the value gets converted to the precision and scale of the target Number Class. If the assignment would create a garbage result, an overflow exception is always thrown. Numbers that are too small (insignificant) never cause exceptions to be thrown. Doing otherwise would be a pain. For example, addition of a number that is too small to have an effect clearly needs to be allowed (e.g. you have a scale of 2 and add.001). Assigning a number which is the result of some calculation that yields a very small number (one too small for the scale of the target Number Class variable) behaves as if the variable has been set to 0. Division by zero: C++ also doesn't detect invalid attempts to divide a number by zero (unless you consider immediately crashing to be a form of error "detection"). This too is a type of error that the Number Class makes easy to trap and handle cleanly, again without a lot of extra code. The Number Class also detects attempts to raise 0 to a negative power. Conversion errors: Another important category of errors is those that can occur when converting back and forth between different types of numeric and character representations. The limited error-handling features of C++'s conversion functions are greatly improved upon in the Base/1 Number Class. 8

9 For example, Number Class conversions discriminate among many specific error types, such as invalid sign, missing digit, negative number converted to an unsigned data type, particular flavors of overflow, etc. You also have the choice of detecting errors either based on a return code or by raising an exception for which you can supply your own handler. Bottom line, you are guaranteed to be warned if the number is too large to be stored or if a desired degree of accuracy (precision) can't be maintained. Using the Number Class prevents the silent destructiveness of overflow that comes with all the C++ numeric data types. But the main point is that Number Class numbers can be large - with many digits to both the left and the right of the decimal point. Having automatic support for larger ranges of numbers often means you avoid the silent damage caused by arithmetic truncation without any special effort dedicated to overflow error detection and handling. Operating System Independent To use the Number Class all you need is an ANSI-compatible C++ compiler. While the Number Class is a component of BFC (Base/1 Foundation Component Library), the class's modular design allows it to be distributed as a separate, standalone product. The Number Class does not depend on BFC. If you have BFC, the Number Class is included. The Base/1 Number Class is compatible with both the Microsoft Foundation Classes (MFC) and the Standard Template Library (STL). You can use the Number Class whether you write Windows/MFC programs with Microsoft's Visual C++ or you program for an STL environment like Unix, using ANSI/C++. The sample code that ships with the product includes MFC and STL based projects, which both execute the same examples of Number Class usage. The Base/1 Number Class is independent of all platforms and operating systems because it is written in ANSI standard C++ and can use the Standard Template Library (STL). The Number Class can be used in various environments like DOS, Windows, UNIX, OS/390 etc., all of which have a standard ANSI/C++ compiler. (We've been careful to use only the most basic C++ features and the standard, public STL interface. In addition, we have upgraded the source code whenever developers have reported minor compilation errors when working with non Microsoft compilers. With the Number Class source code, we supply a small string class, clsstrplus, as a layer between the Number Class and raw MFC and STL strings, and this string class can be easily adapted to handle any peculiarities of the particular STL implementation being used.) Easy To Use Thanks to operator overloading, using the Base/1 Number Class is virtually identical to using built-in C++ number types. The usual arithmetic operators, assignment statements, parameter 9

10 passing, etc. work with Number Class variables just as they work with standard C++ numbers. And, because of Reference Counting, the overhead of using the Number Class is comparable to that of standard C++ data types, so it can be used freely without having to be conscious that it is a user-defined C++ class. But the Number Class has significant advantages over native C++ number types due to these fundamental differences: Number Class as a String: The Number Class (clsnumdbfld) has the convenience of allowing a number to be handled as a string, as well as a number. Using a string provides a way to specify constants that are outside the allowable range of C++ numeric constants. Here are samples of valid assignment statements for the class - clsnumdbfld numtest; numtest = 123; numtest = 1.23; numtest = ; numtest = "123"; numtest = " "; numtest = 0; numtest = "0"; numtest = ""; // null Number class objects can be assigned numeric string values in standard null-terminated C format and can return numeric string values. For example, a number stored in a Number Class object can be returned as a string by doing a cast operation using MFC CString. Here's an example of initializing a Number Class with a string and then verifying that its string value is returned as entered: clsnumdbfld numtmp( " " ); CString strtmp = " "; ASSERT( strtmp!= (CString) numtmp ); // Never asserts. Always equal This code works in the STL implementation because CString is always treated as string, the result of a typedef in the supplied String Plus class header. Instead of CString, you can use the String Plus class (clsstrplus), which is designed to work with MFC's CString or STL's string. The String Plus class adds convenient conversion and assignment routines, trimming, padding, concatenation etc. Here's an example, that handles insignificant left and right 0's correctly. clsnumdbfld numtmp( " " ); clsstrplus strtmp = " "; // insignifcant 0's stripped ASSERT( strtmp!= (clsstrplus) numtmp ); // Never asserts. Always equal 10

11 The Number Class makes null numbers equivalent to null strings, i.e. the first byte is zero ('\0'). IsNull(), which checks if a string is empty or BLANK, is an example of a useful function inherited from clsstrplus. Arithmetic operations on null numbers have the same intuitive behavior as the handling of blanks by spreadsheet programs. That is, null is always treated as ZERO in arithmetic (and NOT as "unknown"). Rounding Behavior of the Number Class: The Number Class handles rounding like a well behaved, floating point number. The last significant digit is rounded up if the next digit is greater than or equal to 5. For example, 1/3 = but 2/3 = When a Number Class has a larger scale (more digits to the right of the decimal point), rounding (NOT trunction) takes place. The RoundNum() function rounds a Number Class's currently held value to a specified scale. Different forms of rounding rules are not needed because of the wide range of numbers supported. With 100 digits of precision available, it's easiest just to adjust the scale (from the default of 8 digits to the right of the decimal point) to one that's large enough so that rounding inaccuracies can be ignored. Overloaded C++ Operators: The Number Class can be used just like a native C++ datatype, with the full spectrum of operators and in all the kinds of numeric expressions supported by C++. The arithmetic operators (+ - * / %) and the comparison operators (==!= > >= < <=) are implemented as global overloaded operators in the header file for Number Class inline functions. For example, the Compare Value function (CompVal) need not be called explicitly for doing comparison. An overloaded comparison operators can be used, which, in turn, causes an inline function call to CompVal(). These operators have to be global. If they were implemented as member functions and not global functions, then the operand on the left hand side would always have to be Number Class object. That would mean that "num1 > 2" would be legal but "2 < num1" would not be. As global functions, both situations are covered by having two functions, the first function take "num1, short" for example and the second function takes "short, num1". Avoiding Garbage from Floating Point Constants: Be aware that when you do assignments to a Number Class objects from floating point constants that you may notice some very small garbage far to the right of the decimal point. In fact, whether that constant is written in scientific notation or standard decimal notation will affect the results. (The different tiny garbage values are due to the low-level C Runtime Library or possibly the hardware floating point unit itself.) 11

12 For example - clsnumdbfld num1( 100, 50 ), num2( 100, 50 ), num3( 100, 50 ); num1 = 9.234e+2; num2 = 9.234e-2; num3 = num1 / num2; num3 equals num1 = 923.4; num2 = ; num3 = num1 / num2; num3 equals In both cases, of course, the value of num3 should be exactly 10,000. To avoid the problem with floating point constants, you can always express the values as "923.4" and ".09234" (string literals) and guarantee accuracy. By expressing decimal numbers without tiny bits of garbage being carried, the Number Class makes extreme precision possible. Speedy Performance Besides simply saving space, the compactness of Base One's Number Class representation provides a performance boost by shortening in-memory data transfers and reducing the amount of disk I/O. But there are additional reasons for significant speedups owing to the unique design of the Base/1 Number Class: All arithmetic calculations are performed taking two digits at a time: Base One's algorithms for operations like addition, subtraction, multiplication, division, remainder, quotient, modulus, etc. have been designed to process digits in a pairwise fashion. On the other hand, Binary Coded Decimal (BCD), which also packs two digits into each byte, requires twice as much work to extract and process each digit individually. Extremely fast numeric comparison logic because no normalization is required: A remarkable feature of the Number Class is that it uses highly efficient byte string operations (exactly like strcmp) to directly compare any pair of numbers. Even if the numbers differ in sign, length, or scale, there is no need for the usual "normalization" step to precede comparison or arithmetic operations. Other numeric encodings (such as BCD) require a great deal of additional processing, digit by digit, to put both numbers into a common intermediate representation before their values can be operated upon. This distinction makes Base One's Number Class much better suited than other technologies for building high-speed searching and sorting applications. 12

13 Reduced memory management overhead: The benefits of "Reference Counting" (discussed above), not only mean that less memory is consumed, but also less processing is required for dynamically allocating and freeing memory when Number Class values are copied between variables. What's more, this memory management logic is implicitly handled by the robust, efficient, underlying STL/MFC string classes. Performance Limitations: The Number Class is slower than double arithmetic because operations are done exclusively through software versus the hardware implementation used for double arithmetic. (Floating point simulation through software is a thing of the past.) Fortunately, tight loops, such as used for simple-minded benchmarks, most often do NOT accurately represent the actual demands on the Number Class. The Number Class is particularly well suited to business systems, which are generally I/O bound, and good results are usually obtained with a blanket substitution of the Number Class for ALL floating point and integer variables. On the other hand, the Number Class is NOT optimized for the kind of number crunching done, for example, in large scale matrix operations. Benchmarks are difficult to make realistic or relevant and difficult to interpret, so we never publish benchmark results. Test results are easily skewed by the way the benchmark is constructed. For example, the order of the tests can slant results because of low-level caching (such as instruction caching, file caching, and virtual memory paging). In some cases, to achieve acceptable performance, you may find it necessary to play games to get the benefit of the Number Class accuracy and the speed of hardware-based floating point arithmetic. That is, you can check programmatically whether you need to use a double and double arithmetic versus the possibly smaller number of instances where you need to use the Number Class and its arithmetic. (Remember to do your performance testing in RELEASE mode and NOT in Debug mode.) Logarithmic, Trigonometric, Exponentiation Functions: The current version of Number Class handles the basic arithmetic operations but does not handle logs, exponentiation (except for positive and negative integral exponents) or trigonometric functions. This is usually NOT a problem because you can intermix standard C++ function calls with Number Class variables. Casting (to double, for example) takes place automatically. (We're still trying to uncover an efficient algorithm for determining values to a specified precision, such as base e raised to any decimal power.) 13

14 Algorithms Used in Number Class Arithmetic The Number Class uses an innovative variable-length encoding of numbers that bears some resemblance to Binary Coded Decimal (BCD), but is considerably more efficient in several respects. One of the keys to Base One's unique design is its use of fast, robust STL/MFC string classes to maintain the internal representation of numbers. This design makes possible a number of features not found in other numeric encoding technologies: - all arithmetic calculations are performed taking two digits at a time - fast byte-by-byte comparison logic requires no normalization to handle variable sign, precision, or scale - no explicit length field is required, reducing both size and processing complexity - significant zeroes are compressed, further reducing storage requirements - compact, efficient memory allocation logic is inherited from the standard STL/MFC string classes - direct collatability of signed numbers of varying length and scale by efficient byte string comparison Exact arithmetic involving very large (or small) numbers is automatically supported and arithmetic can still be done using the convenient, familiar arithmetic operators. The Number class also directly supports the database concept of a null number (all blank), as distinct from a number with a value of zero. (Nulls are not permitted in any C++ numeric data types.) The following diagrams illustrate the algorithms for addition, subtraction, multiplication and division. Unbiased byte values are shown for the sake of clarity, however the actual implementation operates directly upon the biased values of the Number Class internal representation. Number Class Addition Algorithm In brief, addition works as follows - First, the decimal points are aligned by increasing the lesser number's exponent and logically shifting its mantissa to the right by the corresponding number of digits. For the sake of efficiency, a byte offset is maintained to avoid physically shifting by whole bytes. If the difference in exponents is odd, an additional single-digit physical shift is performed on the lesser number. As with all of the Number Class algorithms, the actual computation is performed in units of bytes, i.e. processing two decimal digits at a time from each of the operands. The addition is performed starting from the rightmost end, and the bytes are added with carry, if any. If there is a 14

15 carry at the leftmost end, then the result exponent is incremented by one, and a single-digit shift is applied to remove the leading zero. Finally, any trailing zero bytes are removed, and rounding is done if the result's scale exceeds the scale of the number being operated upon. 15

16 Number Class Subtraction Algorithm In brief, subtraction works as follows - First, the decimal points are aligned by increasing the lesser (in absolute value) number's exponent and logically shifting its mantissa to the right by the corresponding number of digits. For the sake of efficiency, a byte offset is maintained to avoid physically shifting by whole bytes. If the difference in exponents is odd, an additional single- digit physical shift is performed on the lesser number. As with all the Number Class algorithms, the actual computation is performed in units of bytes, i.e. processing two decimal digits at a time from each of the operands. The subtraction is performed starting from the rightmost end, and the bytes are subtracted with carry, if any. Since the lesser number is always subtracted from the greater, there is never a carry beyond the leftmost digit. Any leading zero digits are removed by logically shifting the mantissa leftward and correspondingly decrementing the result's exponent. Finally, any trailing zero bytes are removed, and rounding is done if the result's scale exceeds the scale of the number being operated upon. 16

17 Number Class Multiplication Algorithm In brief, multiplication works as follows - First, the result's sign, maximum length, and tentative exponent are determined, and a buffer of sufficient size is allocated and initialized with zeroes. This buffer is used to accumulate the results of each loop cycle with the un-biased byte values and adds this result to the next result accumulator byte, again processing from right to left. With each successive outer loop cycle the offset of the lowest order (rightmost) result byte computed moves leftward by one byte. (The accumulator holds un-biased byte values while processing is being performed.) Trailing zeroes are always removed, except at most a final zero digit if needed to fill out the last full byte. If the final result accumulator contains a leading zero, this is removed by shifting the mantissa left by a single digit. Otherwise, the tentative exponent is incremented, and the exponent is incremented, and the exponent's final sign and bias are applied. Rounding is done if the result's scale exceeds the scale of the number being operated upon. 17

18 18

19 Number Class Division Algorithm In brief, division works as follows - DoDivide() supports either division or a quotient and/or remainder (modulo) function, depending on whether non-null arguments are supplied. For the quotient and remainder cases, the logic will generarly terminate sooner than full division. (The diagram only shows the details of the division case.) First, the signs of the result, quotient, and remainder are determined. The result's (and quotient's) sign is positive if both the operands have the same sign, otherwise it is negative, and the sign of the remainder is always that of the dividend, i.e. the number being operated upon. The result's exponent is calculated as the difference of the exponents of the dividend and the divisor argument. A maximum number of result mantissa digits is calculated by adding the result's exponent, plus an allowance for the Number Class variable's declared scale factor (i.e. digits to be retained to the right of the decimal point), plus an extra digit to support proper rounding to the desired scale. A result accumulator of sufficient length is allocated and the dividend is copied into this temporary Number Class variable, which will be used as the remaining dividend in the following logic. (For the special case of a quotient/remainder operation, however, the calculation immediately finishes at this point if the divisor is larger than the dividend.) The exponent of the temporary dividend is then adjusted to be the same as that of the divisor. If this leaves the dividend smaller than the divisor, the dividend's exponent is incremented and the result's exponent is decremented, as the final initialization step. (The accumulator is generated with biased mantissa bytes as each result digit is obtained.) The main loop generates one mantissa digit on each cycle, filling the result accumulator from left to right. Each result digit is computed by an inner loop that subtracts the divisor from the dividend, until the remaining dividend is less than (in absolute value) the divisor. Note that these comparison and subtraction operations are performed via Number Class functions, CompAbsVal() and DoSubtract(), since the divisor and dividend are both Number Class objects. The number of subtractions performed by the inner loop yields the next digit of the result. If the remainder is zero, the outer loop terminates; otherwise the remaining dividend is multiplied by 10 and processing for the next result digit continues, up to the required scale and precision. (If obtaining only quotient/remainder, exit when we have calculated all the result digits to the left of the decimal point, i.e. the quotient.) Trailing zeroes are always removed, except at most a last zero digit if needed to fill out the last full byte. A final rounding step is done only if the result's scale exceeds the scale of the number being operated upon. 19

20 Note that the example (1024 / 4) illustrates an instance where the initial temporary dividend (1.024), after forcing its exponent to that of the divisor (0), is smaller than the divisor (4.0), so the dividend's exponent is incremented and the result's exponent is decremented. Thus, the outer loop logic begins it processing against a dividend of

21 Appendix Microsoft Modulo Bugs Over the years of testing of the Number Class, we've discovered nasty bugs in Microsoft's fmod() function, which you can easily confirm for yourself. For example, using the Windows 95 Calculator accessory (evidently built on the same fmod function) try this simple calculation: 5.5 mod 1.1 Instead of giving the correct result, which should be 0, it shows the result as 1.1. Similar errors are not hard to find, e.g. try 5.1 mod 1.7, 49 mod 9.8, 21.9 mod 7.3, and 36 mod 7.2. Interestingly, this problem occurs only with certain choices of values and the pattern of failures is not trivially discerned, but there are obviously many more cases. In fact we found it increasingly rare not to encounter such errors with more decimal places. We were unable to find any reference to this disturbing bug in the Microsoft Knowledge Base. Considering how much flack Intel took over an even more obscure arithmetic bug in its Pentium processor, one can only wonder how Microsoft ever got away with this one. Fortunately, the problem seems to have been quietly fixed in Windows 98, but that's not much consolation to those of us who expect our programs to work properly under Windows 95 and early versions of Windows NT 4.0. In any case, rest assured that the Base/1 Number Class computes the modulo function correctly under any version of Windows. The modulo bug described above seems to have been fixed in the latest operating systems and service packs from Microsoft. However, here's a new one we discovered in recent testing of the Number Class: d1 = ; d2 = ; fmod( d1, d2 ) returns the same value as that of d2 instead of returning zero. In this example, d1 is a perfect multiple of d2 (d1 = d2 * 3). We got this error on Windows NT Service Pack 5 and 6a and Windows 2000 server. For some versions, the bug did NOT appear in the calculator program, but using fmod() ALWAYS produces this bug. The Number Class properly returns the correct remainder of zero. 21

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

ECE 0142 Computer Organization Lecture 3 Floating Point Representations 1 Floating-point arithmetic We often incur floating-point programming. Floating point greatly simplifies working with large (e.g.,

Computer Science 281 Binary and Hexadecimal Review

Computer Science 281 Binary and Hexadecimal Review 1 The Binary Number System Computers store everything, both instructions and data, by using many, many transistors, each of which can be in one of two

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Decimal Division Remember 4th grade long division? 43 // quotient 12 521 // divisor dividend -480 41-36 5 // remainder Shift divisor left (multiply by 10) until MSB lines up with dividend s Repeat until

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

This Unit: Floating Point Arithmetic CIS 371 Computer Organization and Design Unit 7: Floating Point App App App System software Mem CPU I/O Formats Precision and range IEEE 754 standard Operations Addition

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

1 The Java Virtual Machine

1 The Java Virtual Machine About the Spec Format This document describes the Java virtual machine and the instruction set. In this introduction, each component of the machine is briefly described. This

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Divide: Paper & Pencil Computer Architecture ALU Design : Division and Floating Point 1001 Quotient Divisor 1000 1001010 Dividend 1000 10 101 1010 1000 10 (or Modulo result) See how big a number can be

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

Levent EREN levent.eren@ieu.edu.tr A-306 Office Phone:488-9882 INTRODUCTION TO DIGITAL LOGIC

Levent EREN levent.eren@ieu.edu.tr A-306 Office Phone:488-9882 1 Number Systems Representation Positive radix, positional number systems A number with radix r is represented by a string of digits: A n

Object Oriented Software Design

Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

Building Applications Using Micro Focus COBOL

Building Applications Using Micro Focus COBOL Abstract If you look through the Micro Focus COBOL documentation, you will see many different executable file types referenced: int, gnt, exe, dll and others.

Binary Number System. 16. Binary Numbers. Base 10 digits: 0 1 2 3 4 5 6 7 8 9. Base 2 digits: 0 1

Binary Number System 1 Base 10 digits: 0 1 2 3 4 5 6 7 8 9 Base 2 digits: 0 1 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417 = 4 * 10 2 + 1 * 10 1

Base One's Rich Client Architecture

Base One's Rich Client Architecture Base One provides a unique approach for developing Internet-enabled applications, combining both efficiency and ease of programming through its "Rich Client" architecture.

Chapter 2: Elements of Java

Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

Advanced Tutorials. Numeric Data In SAS : Guidelines for Storage and Display Paul Gorrell, Social & Scientific Systems, Inc., Silver Spring, MD

Numeric Data In SAS : Guidelines for Storage and Display Paul Gorrell, Social & Scientific Systems, Inc., Silver Spring, MD ABSTRACT Understanding how SAS stores and displays numeric data is essential

Binary Numbering Systems

Binary Numbering Systems April 1997, ver. 1 Application Note 83 Introduction Binary numbering systems are used in virtually all digital systems, including digital signal processing (DSP), networking, and

Useful Number Systems

Useful Number Systems Decimal Base = 10 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Binary Base = 2 Digit Set = {0, 1} Octal Base = 8 = 2 3 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7} Hexadecimal Base = 16 = 2

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

Inside the CPU how does the CPU work? what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored? some short, boring programs to illustrate the

Testing and Inspecting to Ensure High Quality

Testing and Inspecting to Ensure High Quality Basic definitions A failure is an unacceptable behaviour exhibited by a system The frequency of failures measures the reliability An important design objective

Number Representation

Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data

Attention: This material is copyright 1995-1997 Chris Hecker. All rights reserved. You have permission to read this article for your own education. You do not have permission to put it on your website

Object Oriented Software Design

Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

Systems I: Computer Organization and Architecture

Systems I: Computer Organization and Architecture Lecture 2: Number Systems and Arithmetic Number Systems - Base The number system that we use is base : 734 = + 7 + 3 + 4 = x + 7x + 3x + 4x = x 3 + 7x

Storing Measurement Data

Storing Measurement Data File I/O records or reads data in a file. A typical file I/O operation involves the following process. 1. Create or open a file. Indicate where an existing file resides or where

The programming language C. sws1 1

The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

Chapter 3 Data Storage Objectives After studying this chapter, students should be able to: List five different data types used in a computer. Describe how integers are stored in a computer. Describe how

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen LECTURE 14: DATA STORAGE AND REPRESENTATION Data Storage Memory Hierarchy Disks Fields, Records, Blocks Variable-length

Specifications of Paradox for Windows

Specifications of Paradox for Windows Appendix A 1 Specifications of Paradox for Windows A IN THIS CHAPTER Borland Database Engine (BDE) 000 Paradox Standard Table Specifications 000 Paradox 5 Table Specifications

Java Interview Questions and Answers

1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

The string of digits 101101 in the binary number system represents the quantity

Data Representation Section 3.1 Data Types Registers contain either data or control information Control information is a bit or group of bits used to specify the sequence of command signals needed for

6 3 4 9 = 6 10 + 3 10 + 4 10 + 9 10

Lesson The Binary Number System. Why Binary? The number system that you are familiar with, that you use every day, is the decimal number system, also commonly referred to as the base- system. When you

Raima Database Manager Version 14.0 In-memory Database Engine

+ Raima Database Manager Version 14.0 In-memory Database Engine By Jeffrey R. Parsons, Senior Engineer January 2016 Abstract Raima Database Manager (RDM) v14.0 contains an all new data storage engine optimized

Numbering Systems. InThisAppendix...

G InThisAppendix... Introduction Binary Numbering System Hexadecimal Numbering System Octal Numbering System Binary Coded Decimal (BCD) Numbering System Real (Floating Point) Numbering System BCD/Binary/Decimal/Hex/Octal

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

EE 261 Introduction to Logic Circuits Module #2 Number Systems Topics A. Number System Formation B. Base Conversions C. Binary Arithmetic D. Signed Numbers E. Signed Arithmetic F. Binary Codes Textbook

CHAPTER 5 Round-off errors

CHAPTER 5 Round-off errors In the two previous chapters we have seen how numbers can be represented in the binary numeral system and how this is the basis for representing numbers in computers. Since any

Instruction Set Architecture (ISA)

Instruction Set Architecture (ISA) * Instruction set architecture of a machine fills the semantic gap between the user and the machine. * ISA serves as the starting point for the design of a new machine

IP Subnetting: Practical Subnet Design and Address Determination Example

IP Subnetting: Practical Subnet Design and Address Determination Example When educators ask students what they consider to be the most confusing aspect in learning about networking, many say that it is

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

DNA Data and Program Representation. Alexandre David 1.2.05 adavid@cs.aau.dk

DNA Data and Program Representation Alexandre David 1.2.05 adavid@cs.aau.dk Introduction Very important to understand how data is represented. operations limits precision Digital logic built on 2-valued

Square Roots and Other Radicals

Radicals - Definition Radicals, or roots, are the opposite operation of applying exponents. A power can be undone with a radical and a radical can be undone with a power. For example, if you square 2,

Data Storage 3.1. Foundations of Computer Science Cengage Learning

3 Data Storage 3.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List five different data types used in a computer. Describe how

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Binary Numbers In computer science we deal almost exclusively with binary numbers. it will be very helpful to memorize some binary constants and their decimal and English equivalents. By English equivalents

1 Description of The Simpletron

Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

Software: Systems and Application Software

Software: Systems and Application Software Computer Software Operating System Popular Operating Systems Language Translators Utility Programs Applications Programs Types of Application Software Personal

.NET Standard DateTime Format Strings

.NET Standard DateTime Format Strings Specifier Name Description d Short date pattern Represents a custom DateTime format string defined by the current ShortDatePattern property. D Long date pattern Represents

Fast Arithmetic Coding (FastAC) Implementations

Fast Arithmetic Coding (FastAC) Implementations Amir Said 1 Introduction This document describes our fast implementations of arithmetic coding, which achieve optimal compression and higher throughput by

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

Oracle Academy Introduction to Database Programming with PL/SQL Instructor Resource Guide

Oracle Academy Introduction to Database Programming with Instructor Resource Guide INSTRUCTOR NOTES FOR SLIDES SECTION 1 LESSON 1 Introduction to Slide 1: Introduction to Slide 2: What Will I Learn? Slide

(Refer Slide Time: 02:17)

Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #06 IP Subnetting and Addressing (Not audible: (00:46)) Now,

The Subnet Training Guide

The Subnet Training Guide A Step By Step Guide on Understanding and Solving Subnetting Problems by Brendan Choi v25 easysubnetcom The Subnet Training Guide v25 easysubnetcom Chapter 1 Understanding IP

SQL Server Database Coding Standards and Guidelines

SQL Server Database Coding Standards and Guidelines http://www.sqlauthority.com Naming Tables: Stored Procs: Triggers: Indexes: Primary Keys: Foreign Keys: Defaults: Columns: General Rules: Rules: Pascal

SQL Server An Overview

SQL Server An Overview SQL Server Microsoft SQL Server is designed to work effectively in a number of environments: As a two-tier or multi-tier client/server database system As a desktop database system

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

Introduction to Python

WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

Database Programming with PL/SQL: Learning Objectives

Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs

Chapter 3. Input and output. 3.1 The System class

Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

Information, Entropy, and Coding

Chapter 8 Information, Entropy, and Coding 8. The Need for Data Compression To motivate the material in this chapter, we first consider various data sources and some estimates for the amount of data associated

NUMBER SYSTEMS. William Stallings

NUMBER SYSTEMS William Stallings The Decimal System... The Binary System...3 Converting between Binary and Decimal...3 Integers...4 Fractions...5 Hexadecimal Notation...6 This document available at WilliamStallings.com/StudentSupport.html

Lecture 11: Number Systems

Lecture 11: Number Systems Numeric Data Fixed point Integers (12, 345, 20567 etc) Real fractions (23.45, 23., 0.145 etc.) Floating point such as 23. 45 e 12 Basically an exponent representation Any number

VB.NET Programming Fundamentals

Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

A Second Course in Mathematics Concepts for Elementary Teachers: Theory, Problems, and Solutions

A Second Course in Mathematics Concepts for Elementary Teachers: Theory, Problems, and Solutions Marcel B. Finan Arkansas Tech University c All Rights Reserved First Draft February 8, 2006 1 Contents 25

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

The Clean programming language Group 25, Jingui Li, Daren Tuzi The Clean programming language Overview The Clean programming language first appeared in 1987 and is still being further developed. It was

How To Write A Hexadecimal Program

The mathematics of RAID-6 H. Peter Anvin First version 20 January 2004 Last updated 20 December 2011 RAID-6 supports losing any two drives. syndromes, generally referred P and Q. The way

The mathematics of RAID-6

The mathematics of RAID-6 H. Peter Anvin 1 December 2004 RAID-6 supports losing any two drives. The way this is done is by computing two syndromes, generally referred P and Q. 1 A quick

Binary search tree with SIMD bandwidth optimization using SSE

Binary search tree with SIMD bandwidth optimization using SSE Bowen Zhang, Xinwei Li 1.ABSTRACT In-memory tree structured index search is a fundamental database operation. Modern processors provide tremendous

Module 10. Coding and Testing. Version 2 CSE IIT, Kharagpur

Module 10 Coding and Testing Lesson 23 Code Review Specific Instructional Objectives At the end of this lesson the student would be able to: Identify the necessity of coding standards. Differentiate between

PURSUITS IN MATHEMATICS often produce elementary functions as solutions that need to be

Fast Approximation of the Tangent, Hyperbolic Tangent, Exponential and Logarithmic Functions 2007 Ron Doerfler http://www.myreckonings.com June 27, 2007 Abstract There are some of us who enjoy using our

Data Integrator. Pervasive Software, Inc. 12365-B Riata Trace Parkway Austin, Texas 78727 USA

Data Integrator Event Management Guide Pervasive Software, Inc. 12365-B Riata Trace Parkway Austin, Texas 78727 USA Telephone: 888.296.5969 or 512.231.6000 Fax: 512.231.6010 Email: info@pervasiveintegration.com

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

Table and field properties Tables and fields also have properties that you can set to control their characteristics or behavior.

Create a table When you create a database, you store your data in tables subject-based lists that contain rows and columns. For instance, you can create a Contacts table to store a list of names, addresses,

CSI 333 Lecture 1 Number Systems

CSI 333 Lecture 1 Number Systems 1 1 / 23 Basics of Number Systems Ref: Appendix C of Deitel & Deitel. Weighted Positional Notation: 192 = 2 10 0 + 9 10 1 + 1 10 2 General: Digit sequence : d n 1 d n 2...

RN-Codings: New Insights and Some Applications

RN-Codings: New Insights and Some Applications Abstract During any composite computation there is a constant need for rounding intermediate results before they can participate in further processing. Recently

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

NAND Flash Memories. Using Linux MTD compatible mode. on ELNEC Universal Device Programmers. (Quick Guide)

NAND Flash Memories Using Linux MTD compatible mode on ELNEC Universal Device Programmers (Quick Guide) Application Note April 2012 an_elnec_linux_mtd, version 1.04 Version 1.04/04.2012 Page 1 of 16 As

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

ECE Department Summer LECTURE #5: Number Systems EEL : Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz Decimal Number System: -Our standard number system is base, also

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

Lesson Notes Author: Pamela Schmidt Tables Text Fields (Default) Text or combinations of text and numbers, as well as numbers that don't require calculations, such as phone numbers. or the length set by

CISC 181 Project 3 Designing Classes for Bank Accounts

CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

7 Objectives After completing this lab you will: know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine Introduction Branches and jumps provide ways to change

How To Write Portable Programs In C

Writing Portable Programs COS 217 1 Goals of Today s Class Writing portable programs in C Sources of heterogeneity Data types, evaluation order, byte order, char set, Reading period and final exam Important

Base Conversion written by Cathy Saxton

Base Conversion written by Cathy Saxton 1. Base 10 In base 10, the digits, from right to left, specify the 1 s, 10 s, 100 s, 1000 s, etc. These are powers of 10 (10 x ): 10 0 = 1, 10 1 = 10, 10 2 = 100,

Glossary of Object Oriented Terms

Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

Lecture 2. Binary and Hexadecimal Numbers

Lecture 2 Binary and Hexadecimal Numbers Purpose: Review binary and hexadecimal number representations Convert directly from one base to another base Review addition and subtraction in binary representations

5 Arrays and Pointers

5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of

General Software Development Standards and Guidelines Version 3.5

NATIONAL WEATHER SERVICE OFFICE of HYDROLOGIC DEVELOPMENT Science Infusion Software Engineering Process Group (SISEPG) General Software Development Standards and Guidelines 7/30/2007 Revision History Date

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping 3.1.1 Constants, variables and data types Understand what is mean by terms data and information Be able to describe the difference

1. The Fly In The Ointment

Arithmetic Revisited Lesson 5: Decimal Fractions or Place Value Extended Part 5: Dividing Decimal Fractions, Part 2. The Fly In The Ointment The meaning of, say, ƒ 2 doesn't depend on whether we represent

Oracle Database: SQL and PL/SQL Fundamentals

Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

2/9/9 Binary number system Computer (electronic) systems prefer binary numbers Binary number: represent a number in base-2 Binary numbers 2 3 + 7 + 5 Some terminology Bit: a binary digit ( or ) Hexadecimal

Fast Logarithms on a Floating-Point Device

TMS320 DSP DESIGNER S NOTEBOOK Fast Logarithms on a Floating-Point Device APPLICATION BRIEF: SPRA218 Keith Larson Digital Signal Processing Products Semiconductor Group Texas Instruments March 1993 IMPORTANT

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

Summation Algebra. x i

2 Summation Algebra In the next 3 chapters, we deal with the very basic results in summation algebra, descriptive statistics, and matrix algebra that are prerequisites for the study of SEM theory. You

PGR Computing Programming Skills

PGR Computing Programming Skills Dr. I. Hawke 2008 1 Introduction The purpose of computing is to do something faster, more efficiently and more reliably than you could as a human do it. One obvious point

Domains and Competencies

Domains and Competencies DOMAIN I TECHNOLOGY APPLICATIONS CORE Standards Assessed: Computer Science 8 12 I VII Competency 001: The computer science teacher knows technology terminology and concepts; the

SQL Server Array Library 2010-11 László Dobos, Alexander S. Szalay

SQL Server Array Library 2010-11 László Dobos, Alexander S. Szalay The Johns Hopkins University, Department of Physics and Astronomy Eötvös University, Department of Physics of Complex Systems http://voservices.net/sqlarray,

Wave Analytics Data Integration

Wave Analytics Data Integration Salesforce, Spring 16 @salesforcedocs Last updated: April 28, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

MPLAB TM C30 Managed PSV Pointers Beta support included with MPLAB C30 V3.00 Contents 1 Overview 2 1.1 Why Beta?.............................. 2 1.2 Other Sources of Reference..................... 2 2