cs33-floatingpoint

cs33-floatingpoint - loating Point loating Point Floating...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: loating Point loating Point Floating Point Floating Point Chapter 2 of B&O Some notes adopted from Bryant and OHallaron Floating Point Puzzles Floating Point Puzzles For each of the following C expressions, either: Argue that it is true for all argument values xplain why not true Explain why not true x == (int)(float) x x == (int)(double) x int x = ; f == (float)(double) f d == (float) d ) float f = ; double d = ; f == -(-f); 2/3 == 2/3.0 d < 0.0 ((d*2) < 0.0) Assume neither d nor f is NaN d > f -f > -d d * d >= 0.0 (d+f)-d == f Fractional Binary Numbers Fractional Binary Numbers 2 i 1 2 i 1 2 4 b i b i 1 b 2 b 1 b b 1 b 2 b 3 b j . 1/2 /4 1/4 1/8 2 j Representation Bits to right of binary point represent fractional i powers of 2 Represents rational number: b k 2 k k j Frac. Binary Number Examples Frac. Binary Number Examples Value Representation 5 3 / 4 101.11 2 2 7 / 8 10.111 2 63 / 64 0.111111 2 Observations Divide by 2 by shifting right Multiply by 2 by shifting left Numbers of form 0.111111 2 just below 1.0 /2 1/4 1/8 1/2 1/2 + 1/4 + 1/8 + + 1/2 i + 1.0 Representable Numbers Representable Numbers Limitation Can only exactly represent numbers of the form x /2 k Other numbers have repeating bit representations alue epresentation Value Representation 1/3 0.0101010101[01] 2 /5 001100110011[0011] 1/5 0.001100110011[0011] 2 1/10 0.0001100110011[0011] 2 IEEE Floating Point IEEE Floating Point IEEE Standard 754 Established in 1985 as uniform standard for floating point arithmetic Before that, many idiosyncratic formats Supported by all major CPUs Driven by Numerical Concerns Nice standards for rounding, overflow, underflow Hard to make go fast Numerical analysts predominated over hardware types in defining standard Floating Point Representation Floating Point Representation Numerical Form 1 s M 2 E Sign bit s determines whether number is negative or positive Significand M normally a fractional value in range [1.0,2.0). xponent eights value by power of two Exponent E weights value by power of two Encoding xp rac MSB is sign bit xp eld encodes s exp frac exp field encodes E frac field encodes M Floating Point Precisions Floating Point Precisions Encoding s exp frac MSB is sign bit exp field encodes E frac field encodes M Sizes Single precision: 8 exp bits, 23 frac bits 32 bits total Double precision: 11 exp bits, 52 frac bits 64 bits total Normalized Numeric Values Normalized Numeric Values Condition e x p 0000 and exp 1111 ponent coded as biased value Exponent coded as biased value E = Exp Bias Exp : unsigned value denoted by exp Bias : Bias value Single precision: 127 (Exp: 1254, E:...
View Full Document

Page1 / 31

cs33-floatingpoint - loating Point loating Point Floating...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online