Lecture 4

# 50 1 1 2 2 250 2 2 3 2 150

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: make it ﬁt into desired precision: §  §  Possibly overﬂow if exponent too large Possibly drop least-­‐signiﬁcant bits of signiﬁcand to ﬁt 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 ﬂoa=ng-­‐point Floa-ng Point Opera-ons University of Washington Mathema-cal Proper-es of FP Opera-ons ¢  ¢  If overﬂow 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 ﬂoa-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 oﬀers two levels of precision float double ¢  ¢  ¢  single precision (32-­‐...
View Full Document

## This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online