50 1 1 2 2 250 2 2 3 2 150

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: make it fit into desired precision: §  §  Possibly overflow if exponent too large Possibly drop least-­‐significant bits of significand to fit into frac Floa-ng Point Opera-ons University of Washington Rounding modes ¢  Possible rounding modes (illustrated with dollar rounding): §  Round-­‐toward-­‐zero §  Round-­‐down (-­‐∞) §  Round-­‐up (+∞) §  Round-­‐to-­‐nearest §  Round-­‐to-­‐even ¢  $1.40 $1 $1 $2 $1 $1 $1.60 $1 $1 $2 $2 $2 $1.50 $1 $1 $2 ?? $2 $2.50 $2 $2 $3 ?? $2 –$1.50 –$1 –$2 –$1 ?? –$2 What could happen if we’re repeatedly rounding the results of our opera-ons? §  If we always round in the same direc=on, we could introduce a sta=s=cal bias into our set of values! ¢  Round-­‐to-­‐even avoids this bias by rounding up about half the -me, and rounding down about half the -me §  Default rounding mode for IEEE floa=ng-­‐point Floa-ng Point Opera-ons University of Washington Mathema-cal Proper-es of FP Opera-ons ¢  ¢  If overflow of the exponent occurs, result will be ∞ or -­‐∞ Floats with value ∞, -­‐∞, and NaN can be used in opera-ons §  Result is usually s=ll ∞, -­‐∞, or NaN; some=mes intui=ve, some=mes not ¢  Floa-ng point opera-ons are not always associa-ve or distribu-ve, due to rounding! §  (3.14 + 1e10) -­‐ 1e10 != 3.14 + (1e10 -­‐ 1e10) §  1e20 * (1e20 -­‐ 1e20) != (1e20 * 1e20) -­‐ (1e20 * 1e20) Floa-ng Point Opera-ons University of Washington Integer & Floa-ng Point Numbers ¢  ¢  ¢  ¢  ¢  ¢  ¢  ¢  Representa-on of integers: unsigned and signed Unsigned and signed integers in C Arithme-c and shiBing Sign extension Background: frac-onal binary numbers IEEE floa-ng-­‐point standard Floa-ng-­‐point opera-ons and rounding Floa-ng-­‐point in C Floa-ng Point in C University of Washington Floa-ng Point in C ¢  C offers two levels of precision float double ¢  ¢  ¢  single precision (32-­‐...
View Full Document

Ask a homework question - tutors are online