Computer Science A 14: 3/4
Computing with numbers - Precision - Representation - Computing with numbers - Example
Floating point numbers Number with an integer part and decimals And very large numbers with out all digits And very small numbers near zero Ide: represent numbers as sign and two numbers sign * decimal part * 10 exponent
Unique representation 1*10 0 = 10*10 -1 =.. Numbers must be normalized to be on the form sign*0,decimals*10 exponent Where decimal part must not start with zero Or decimal part and exponent is zero and the number is zero
Float Float: 4bytes = 32 bit Exponent 8 bits: Decimal part: 23 bits (+1) + sign Precision: 2 24 =2 10 *2 10 *2 4 ≈ about 7 digits Interval: ≈ 10 ? +eeeeeee e
Dobbelt præcision double: 64 bit or 8 bytes 11 bit exponent (up to ) 52 bit decimal part (about 15 digits)
Cmputing with numbers Floating point numbers are nor precise. With repeated computation rounding errors may accumulate Do not compare with equality (==) but check that the difference is less than a small value. Do not subtract two almost equal values. Redesign instead the algorithm. Avoid repeated adding of numbers
Rounding errors If you need higher precision you need more space You need a sense of bit patterns, powers of two and knowledge of the internal representation If you need to calculate with floating point numbers be aware of the traps