Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by 3 1 <= mantissa < <= mantissa < 1000 The x10 n portion is replaced by a “units prefix” The x10 n portion is replaced by a “units prefix”Examples: 3495V -> 3.495kV 3495V -> 3.495kV A -> 87.63uA A -> 87.63uA Engineering Output
int PutV_Eng(double v, int sigfigs, char *units) v : Value to be output sigfigs : number of sig figs to display units : string containing the units name to append. RETURNS: Number of characters printed. Engineering Output Function
SI Standard Prefixes ScalePrefixScalePrefix 10 3 kkilo mmilli 10 6 MMega umicro 10 9 GGiga nnano TTera ppico PPeta ffemto EExa aatto ZZetta zzepto YYotta yyocto
Measure of the accuracy and/or precision of a value. Values are assumed known to +/- 0.5 sig fig. Values are assumed known to +/- 0.5 sig fig. Determines how many digits are reported. Determines how many digits are reported. By convention, a leading 1 is not considered significant. By convention, a leading 1 is not considered significant. By convention, trailing zeroes not considered significant. By convention, trailing zeroes not considered significant.Examples: 3.495kV has 4 sig figs kV has 4 sig figs uA has 3 sig figs uA has 3 sig figs. 400m has 1 sig fig. (unless told otherwise). 400m has 1 sig fig. (unless told otherwise). Significant Figures
Round to nearest least significant digit. Visually, we look to see if the next digit is 5 or greater. Visually, we look to see if the next digit is 5 or greater. Our output algorithm automatically truncates (ignores) any digits to the right of the last digit output. Our output algorithm automatically truncates (ignores) any digits to the right of the last digit output. Algorithmically, we can simply add 0.5 sig fig and truncate. Algorithmically, we can simply add 0.5 sig fig and truncate.Examples: rounds to with 4 sig. figs rounds to with 4 sig. figs = | 93 (only output 4 digits) = | 93 (only output 4 digits) rounds to 2.39 with 3 sig figs rounds to 2.39 with 3 sig figs = 2.39 | 454 (only output 3 digits) = 2.39 | 454 (only output 3 digits) Rounding
In scientific notation, the value v can be expressed using a mantissa (m) and an exponent (e) as follows: v = m x 10 e This value is normalized if m has exactly one non-zero digit to the left of the decimal point, i.e, if: 1.0 <= m < 10.0 Ignoring significant of leading 1 (for now), 0.5 sig fig is then: hsf = 5 x 10 -N (hsf - “hemi-sig fig) If m has a leading 1, then hsf is another factor of ten smaller: hsf = 0.5 x 10 -N Rounding Normalized Values
1) TASK: Output negative sign and take absolute value. 2) TASK: Determine the mantissa and the exponent. 3) TASK: Add 0.5 Sig Fig to Mantissa 4) TASK: Scale mantissa so that exponent is divisible by 3. 5) TASK: Output mantissa to N sig figs. 6) TASK: Output prefix based on exponent. 7) TASK: Output units. 8) TASK: Return number of characters printed. Top Level Decomposition
v = to 4 sig figs 1) TASK: Output negative sign and take absolute value. OUTPUT: ‘-’ v = ) TASK: Determine the mantissa and the exponent. m = e = -5 3) TASK: Add 0.5 Sig Fig to Mantissa hsf = 5 x = hsf = hsf/10 = (since m < 2) m = m + hsf = = Hand Example
4) TASK: Scale mantissa so that exponent is divisible by 3. e = -4 not divisible by 3. Multiply mantissa by 10 and decrement exponent until it is. m = e = -3 5) TASK: Output mantissa to N sig figs. Output m to (N+1 digits since leading digit was a 1) OUTPUT: ) TASK: Output prefix based on exponent. OUTPUT: m 7) TASK: Output units. Hand Example (cont’d)
int PutV_Eng(double v, int sigfigs, char *units) { int i, c, e; double m, hsf; /* TASK 1 - Handle negative values */ if (n < 0.0) {PutC(‘-’); return 1 + PutV_Eng(-v, sigfigs, units); } PutV_Eng() Task 1
/* TASK 2 - Determine mantissa and exponent */ m = 0.0; e = 0; if (v != 0.0) { while (v >= 10.0) { v /= 10.0; e++;} while (v < 1.0) { v *= 10.0; e--;}} PutV_Eng() Task 2
/* TASK 3 - Add 0.5 sig fig */ hsf = (m < 2.0)? 0.5 : 5.0; for (i = 0; i < sigfigs; i++) hsf /= 10.0; PutV_Eng() Task 3
/* TASK 4 - Make exponent divisible by 3 */ while (e%3) { m *= 10.0; e--;} PutV_Eng() Task 4
/* TASK 5 - Output Mantissa */ c = PutV_lfN(m, sigfigs + ((m<2.0)? 1 : 0) ); /* The PutV_lfN() function is basically The PutV_lfN() function is basically the PutV_lf() function except that it the PutV_lf() function except that it only puts out N digits (followed by only puts out N digits (followed by trailing zeros if necessary). trailing zeros if necessary).*/ PutV_Eng() Task 5
/* TASK 6 - Output Prefix */ switch(e){ case -24: PutC(‘y’); c++; break; case -21: PutC(‘z’); c++; break; /*... */ case -3: PutC(‘m’); c++; break; case 0: break; case 3: PutC(‘k’); c++; break; /*... */ case 21: PutC(‘Z’); c++; break; case 24: PutC(‘Y’); c++; break; default: PutC(‘e’); c += 1 + PutV_i(e); } PutV_Eng() Task 6
/* TASK 7 - Output Units */ c += PutS(units); /* TASK 8 - Return number of characters */ return c; } PutV_Eng() Task 7 / 8