This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
pdclib:floatingpoint [2019/10/09 14:10] solar [Fixed Point] |
pdclib:floatingpoint [2019/10/21 10:13] (current) solar [Floating-Point Printout] |
||
---|---|---|---|
Line 157: | Line 157: | ||
Steele & White approach the presentation of their Dragon algorithm as a series of " | Steele & White approach the presentation of their Dragon algorithm as a series of " | ||
- | ==== Fixed Point ==== | + | ==== Fixed Point Fraction Output |
Given: | Given: | ||
Line 176: | Line 176: | ||
- Each digit of //F// is output before the next is generated; no "back up" for corrections. | - Each digit of //F// is output before the next is generated; no "back up" for corrections. | ||
- | Algorithm: | + | Algorithm |
* <m>k = 0, R = f, M = { b ^ { -n } / 2 }</m> | * <m>k = 0, R = f, M = { b ^ { -n } / 2 }</m> | ||
Line 193: | Line 193: | ||
* append( F, U + 1 ) | * append( F, U + 1 ) | ||
- | At the end, < | + | At the end, < |
+ | |||
+ | Example: | ||
+ | |||
+ | * Given the base <m>b = 2</m> number <m>f = .10110</ | ||
+ | * The //exact// decimal representation would be < | ||
+ | * The next higher number (< | ||
+ | * The next lower number (< | ||
+ | * The Mask would be <m>M = { b ^ {-n} } / 2 = { 2 ^ { -5 } } / 2 = 0.015625</ | ||
+ | |||
+ | * First (<m>k = 1</ | ||
+ | * multiply <m>R = 0.6835</ | ||
+ | * multiply <m>M = 0.015625</ | ||
+ | * Fractional part < | ||
+ | * Second (<m>k = 2</ | ||
+ | * multiply <m>R = 0.835</ | ||
+ | * multiply <m>M = 0.15625</ | ||
+ | * Fractional part < | ||
+ | * Post-loop | ||
+ | * Fractional part < | ||
+ | * We have <m>N = k = 2</m> fractional digits in our result of < | ||
+ | |||
+ | ==== Floating-Point Printout ==== | ||
+ | |||
+ | Given: | ||
+ | |||
+ | * A base //b// floating-point number <m>v = f * b ^ (e - p)</ | ||
+ | |||
+ | Output: | ||
+ | |||
+ | * An approximate representation to base //B//, using exponential notation if the value is very large or very small. | ||
+ | |||
+ | Algorithm (Dragon2): | ||
+ | |||
+ | * Compute <m>v prime = v * B ^ {-x}</ | ||
+ | * Print the integer part of <m>v prime</ | ||
+ | * Print a decimal point | ||
+ | * Take the fractional part of <m>v prime</ | ||
+ | * Apply algorithm < | ||
+ | * If < |