cs lecture oct 7 2010

cs lecture oct 7 2010 - Scientific notations -2.6307 x...

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

View Full Document Right Arrow Icon
Scientific notations -2.6307 x 10^30 inc C: float x; single precision floating point 32 bits double ; double precision floating point 64 bits. #include <stdio.h> int main(void) { double x=-2.6302e30; printf(%d//n”,sizeof(float)); =>4 printf(“%d\n”,sizeof(double));=>5 printf(%f\n”,x); =>-26302000000000001035938475983749.00000000 printf(%e\n,x); =>-2.630e30 printf(“%g\n”,x);=>2.630e+30 IEEE floating point standard 63 (sign, 1bit) 53 0 double [][][][][][][][][][][][][][][][][][][][][][][][][][][][] signs 63-52:expoinent (with sign, 11 bits) fraction (51-0), 52 bits. value (O-1) sign x fraction x 2(exponent) (sort of) Floating point provides an approximate representation for real numbers (ie, no irrational numbers); Error in floating point numbers r-real number you’re trying to approximate eg Pi p – floating point representation absolute error |r-p| eg |Pi-3.14| = 0.00159265358979 relative error eg |r-p|/|r| eg |pi-3.14|/|pi| = 0.0005670 Relative error can be large even when error is small. avoid:
Background image of page 1

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

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

This note was uploaded on 12/10/2011 for the course CS 137 taught by Professor Clarke during the Fall '10 term at Waterloo.

Page1 / 3

cs lecture oct 7 2010 - Scientific notations -2.6307 x...

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

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