This preview shows page 1. Sign up to view the full content.
Unformatted text preview: bit) double precision (64-‐bit) Default rounding mode is round-‐to-‐even #include <math.h> to get INFINITY and NAN constants Equality (==) comparisons between ﬂoa-ng point numbers are tricky, and oBen return unexpected results § Just avoid them! § Subs=tute things like: (abs(x-‐y) / max(abs(x),abs(y))) < epsilon §
§ Not guaranteed – depends on what you’re doing, the data, etc. When in doubt, ﬁnd a trained Numerical Analyst or use a carefully-‐
wri[en library Floa-ng Point in C University of Washington Floa-ng Point in C ¢ Conversions between data types: § Cas=ng between int, float, and double changes the bit representa=on!! § int → float
§ May be rounded; overﬂow not possible § int → double or float → double
§ Exact conversion, as long as int has ≤ 53-‐bit word size § double or float → int
§ Truncates frac=onal part (rounded toward zero) § Not deﬁned when out of range or NaN: generally sets to Tmin Floa-ng Point in C University of Washington Summary ¢ Zero 0 00000000 0000000000000000000000
¢ Normalized values s
¢ 1 to 2k-...
View Full Document
- Fall '09