Numbers used in finance, carpentry, science and programming
- Mixed numbers with fractions
- 3 5/16 is 3.3125
- The North Carolina Standard Course of Study K-8 Mathematics requires that:
- 7th graders be able to “Convert a fraction to a decimal using long division.”
- Scientific notation
float
literals in FORTRAN, C and Java resemble scientific notation.- The North Carolina Standard Course of Study K-8 Mathematics requires that:
- 8th graders be able to “Perform multiplication and division with numbers expressed in scientific notation to solve real-world problems, including problems where both decimal and scientific notation are used.”
SI Prefixes
Using exponents
Algorithms for elementary arithemetic
Refresh your knowledge of the four basic operations.
- Addition
- The elementary school algorithm, called ripple carry by computer engineers, requires time O(n) and space O(n).
- Computers use carry lookahead adders that require time O(log n) and space O(n).
- Subtraction
- The American elementary school algorithm can be a tad confusing, especially which many borrows are required, as in 2000-13.
- The elementary school algorithm also requires that you first compare the sign. For example, 128-2018 is computed as -(2018-128).
- Computers calculate a-b as a+(-b). This is similar to using nine’s complement.
- Computers do not use “sign magnitude” numbers. You’ll learn about two’s-complement in Chapter 2.
- Multiplication
- Start by memorizing your multiplication tables!
- The Penrose (NC) Elementary School algorithm requires time O(n2) and paper space O(n2).
- Today North Carolina schools often use lattice multiplication. It’s first known use was about 700 years ago by Ibn al‐Bannāʾ al‐Marrākushī al-Azdi.
- Peasant Multiplication is an ancient binary-based algorithm that some say is 4000 years old.
- Older (and cheaper) computers use shift-and-add multipliers but the fast ones implement lattice muliplication using array multipliers which requires O(n) time but O(n2) space.
- Division
- Division is hard and often slow.
- The Pentium FDIV bug cost Intel about $475,000,000.
Douglas Jones
has a page,
Beyond Integer Addition and Subtraction,
showing how multiplication and division can be implemented
with C loops without using the *
and /
.
This is useful because some really cheap computers do not have
”machine-level“ implementations of these operators.