Title: Engineering Output
1Engineering Output
- Engineering Notation
- Similar to scientific notation.
- Exponent is evenly divisible by 3
- 1 lt mantissa lt 1000
- The x10n portion is replaced by a units prefix
- Examples
- 3495V -gt 3.495kV
- 0.00008763A -gt 87.63uA
2Engineering Output Function
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.
3SI Standard Prefixes
Scale Prefix Prefix Scale Prefix Prefix
103 k kilo 10-3 m milli
106 M Mega 10-6 u micro
109 G Giga 10-9 n nano
1012 T Tera 10-12 p pico
1015 P Peta 10-15 f femto
1018 E Exa 10-18 a atto
1021 Z Zetta 10-21 z zepto
1024 Y Yotta 10-24 y yocto
4Significant Figures
- Measure of the accuracy and/or precision of a
value. - Values are assumed known to /- 0.5 sig fig.
- Determines how many digits are reported.
- By convention, a leading 1 is not considered
significant. - By convention, trailing zeroes not considered
significant. - Examples
- 3.495kV has 4 sig figs.
- 17.63uA has 3 sig figs.
- 400m has 1 sig fig. (unless told otherwise).
5Rounding
- Round to nearest least significant digit.
- 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. - Algorithmically, we can simply add 0.5 sig fig
and truncate. - Examples
- 4.53243 rounds to 4.532 with 4 sig. figs.
- 4.53243 0.0005 4.532 93 (only output 4
digits) - 2.38954 rounds to 2.39 with 3 sig figs.
- 2.38954 0.005 2.39 454 (only output 3
digits)
6Rounding Normalized Values
In scientific notation, the value v can be
expressed using a mantissa (m) and an exponent
(e) as follows v m x 10e This value is
normalized if m has exactly one non-zero digit to
the left of the decimal point, i.e, if 1.0 lt m
lt 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
7Top Level Decomposition
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.
8Hand Example
v -0.00001846774 to 4 sig figs 1) TASK Output
negative sign and take absolute value. OUTPUT
- v 0.00001846774 2) TASK Determine the
mantissa and the exponent. m 1.846774 e
-5 3) TASK Add 0.5 Sig Fig to Mantissa hsf 5
x 10-4 0.0005 hsf hsf/10 0.00005 (since m
lt 2) m m hsf 1.846774 0.00005 1.846824
9Hand Example (contd)
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 18.46824 e -3 5) TASK
Output mantissa to N sig figs. Output m to (N1
digits since leading digit was a 1) OUTPUT
18.468 6) TASK Output prefix based on
exponent. OUTPUT m 7) TASK Output units.
10PutV_Eng() Task 1
int PutV_Eng(double v, int sigfigs, char
units) int i, c, e double m, hsf /
TASK 1 - Handle negative values / if (n lt
0.0) PutC(-) return 1 PutV_Eng(-v,
sigfigs, units)
11PutV_Eng() Task 2
/ TASK 2 - Determine mantissa and exponent
/ m 0.0 e 0 if (v ! 0.0) while (v
gt 10.0) v / 10.0 e while (v
lt 1.0) v 10.0 e--
12PutV_Eng() Task 3
/ TASK 3 - Add 0.5 sig fig / hsf (m lt 2.0)?
0.5 5.0 for (i 0 i lt sigfigs i) hsf
/ 10.0
13PutV_Eng() Task 4
/ TASK 4 - Make exponent divisible by 3
/ while (e3) m 10.0 e--
14PutV_Eng() Task 5
/ TASK 5 - Output Mantissa / c PutV_lfN(m,
sigfigs ((mlt2.0)? 1 0) ) / The
PutV_lfN() function is basically the
PutV_lf() function except that it only puts
out N digits (followed by trailing zeros if
necessary). /
15PutV_Eng() Task 6
/ 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)
16PutV_Eng() Task 7 / 8
/ TASK 7 - Output Units / c
PutS(units) / TASK 8 - Return number of
characters / return c