Harvey Mudd CS 105 - Floating Point

Unformatted text preview:

Floating PointIEEE Floating PointFractional Binary NumbersFrac. Binary Number ExamplesRepresentable NumbersFloating Point RepresentationFloating Point Precisions“Normalized” Numeric ValuesNormalized Encoding ExFloating Point OperationsFloating Point in CAriane 5SummaryFloating PointTopicsTopicsOverview of Floating Pointfloats.pptCS 105“Tour of the Black Holes of Computing!”– 2 –CS 105IEEE Floating PointIEEE Floating PointIEEE Standard 754IEEE Standard 754Established in 1985 as uniform standard for floating point arithmeticBefore that, many idiosyncratic formatsSupported by all major CPUsDriven by Numerical ConcernsDriven by Numerical ConcernsNice standards for rounding, overflow, underflowHard to make go fastNumerical analysts predominated over hardware types in defining standard– 3 –CS 105Fractional Binary NumbersFractional Binary NumbersRepresentationRepresentationBits to right of “binary point” represent fractional powers of 2Represents rational number:bibi–1b2b1b0b–1b–2b–3b–j• • •• • • .1242i–12i• • •• • •1/21/41/82–jbk2kk  ji– 4 –CS 105Frac. Binary Number ExamplesFrac. Binary Number ExamplesValueValueRepresentationRepresentation5-3/4 101.1122-7/8 10.111263/64 0.1111112ObservationsObservationsDivide by 2 by shifting rightMultiply by 2 by shifting leftNumbers of form 0.111111…2 just below 1.01/2 + 1/4 + 1/8 + … + 1/2i + …  1.0Use notation 1.0 – – 5 –CS 105Representable NumbersRepresentable NumbersLimitationLimitationCan only exactly represent numbers of the form x/2kOther numbers have repeating bit representationsValueValueRepresentationRepresentation1/3 0.0101010101[01]…21/5 0.001100110011[0011]…21/10 0.0001100110011[0011]…2– 6 –CS 105Numerical FormNumerical Form–1s M 2ESign bit s determines whether number is negative or positiveSignificand M normally a fractional value in range [1.0,2.0).Exponent E weights value by power of twoEncodingEncodingMSB is sign bitexp field encodes Efrac field encodes MFloating Point RepresentationFloating Point Representations exp frac– 7 –CS 105EncodingEncodingMSB is sign bitexp field encodes Efrac field encodes MSizesSizesSingle precision: 8 exp bits, 23 frac bits32 bits totalDouble precision: 11 exp bits, 52 frac bits64 bits totalExtended precision: 15 exp bits, 63 frac bitsOnly found in Intel-compatible machinesStored in 80 bits»1 bit wastedFloating Point PrecisionsFloating Point Precisionss exp frac– 8 –CS 105“Normalized” Numeric Values“Normalized” Numeric ValuesConditionConditionexp  000…0 and exp  111…1Exponent coded as Exponent coded as biasedbiased value valueE = Exp – BiasExp : unsigned value denoted by exp Bias : Bias value»Single precision: 127 (Exp: 1…254, E: -126…127)»Double precision: 1023 (Exp: 1…2046, E: -1022…1023)»in general: Bias = 2e-1 - 1, where e is number of exponent bitsSignificand coded with implied leading 1Significand coded with implied leading 1M = 1.xxx…x2xxx…x: bits of fracMinimum when 000…0 (M = 1.0)Maximum when 111…1 (M = 2.0 – )Get extra leading bit for “free”– 9 –CS 105Normalized Encoding Ex Normalized Encoding Ex ValueValueFloat F = 15213.0;1521310 = 111011011011012 = 1.11011011011012 X 213SignificandSignificandM = 1.11011011011012frac= 110110110110100000000002ExponentExponentE = 13Bias = 127Exp = 140 = 100011002Floating Point Representation (Class 02):Hex: 4 6 6 D B 4 0 0 Binary: 0100 0110 0110 1101 1011 0100 0000 0000140: 100 0110 015213: 1110 1101 1011 01– 10 –CS 105Floating Point OperationsFloating Point OperationsConceptual ViewConceptual ViewFirst compute exact resultMake it fit into desired precisionPossibly overflow if exponent too largePossibly round to fit into fracRounding Modes (illustrate with $ rounding)Rounding Modes (illustrate with $ rounding)$1.40$1.40$1.60$1.60$1.50$1.50$2.50$2.50–$1.50–$1.50Zero $1 $1 $1 $2 –$1Round down (- ) $1 $1 $1 $2 –$2Round up (+ ) $2 $2 $2 $3 –$1Nearest Even (default) $1 $2 $2 $2 –$2Note:1. Round down: rounded result is close to but no greater than true result.2. Round up: rounded result is close to but no less than true result.– 11 –CS 105Floating Point in CFloating Point in CC Guarantees Two LevelsC Guarantees Two Levelsfloat single precisiondouble double precisionConversionsConversionsCasting between int, float, and double changes numeric values Double or float to intTruncates fractional partLike rounding toward zeroNot defined when out of range»Generally saturates to TMin or TMax int to doubleExact conversion, as long as int has ≤ 53 bit word size int to floatWill round according to rounding mode– 12 –CS 105Ariane 5Ariane 5Exploded 37 seconds after liftofCargo worth $500 millionWhyWhyComputed horizontal velocity as floating point numberConverted to 16-bit integerWorked OK for Ariane 4Overflowed for Ariane 5Used same software– 13 –CS 105SummarySummaryIEEE Floating Point Has Clear Mathematical PropertiesIEEE Floating Point Has Clear Mathematical PropertiesRepresents numbers of form M X 2ECan reason about operations independent of implementationAs if computed with perfect precision and then roundedNot the same as real arithmeticViolates associativity/distributivityMakes life difficult for compilers & serious numerical applications


View Full Document

Harvey Mudd CS 105 - Floating Point

Documents in this Course
Processes

Processes

25 pages

Processes

Processes

27 pages

Load more
Download Floating Point
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Floating Point and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Floating Point 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?