Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is...

16
Engineering Notation: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by 3 1 <= mantissa < 1000 1 <= mantissa < 1000 The x10 The x10 n portion is replaced by a “units portion is replaced by a “units prefix” prefix” Examples: Examples: 3495V -> 3.495kV 3495V -> 3.495kV 0.00008763A -> 87.63uA 0.00008763A -> 87.63uA Engineering Output

Transcript of Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is...

Page 1: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

Engineering Notation:Engineering Notation:

• Similar to scientific notation.Similar to scientific notation.

• Exponent is evenly divisible by 3Exponent is evenly divisible by 3

• 1 <= mantissa < 10001 <= mantissa < 1000

• The x10The x10nn portion is replaced by a “units prefix”portion is replaced by a “units prefix”

Examples:Examples:

• 3495V -> 3.495kV3495V -> 3.495kV

• 0.00008763A -> 87.63uA0.00008763A -> 87.63uA

Engineering OutputEngineering Output

Page 2: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

int PutV_Eng(double v, int sigfigs, char *units)int PutV_Eng(double v, int sigfigs, char *units)

v : Value to be outputv : Value to be outputsigfigs : number of sig figs to displaysigfigs : number of sig figs to displayunits : string containing the units name to append.units : string containing the units name to append.

RETURNS: Number of characters printed.RETURNS: Number of characters printed.

Engineering Output FunctionEngineering Output Function

Page 3: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

SI Standard PrefixesSI Standard Prefixes

ScaleScale PrefixPrefix ScaleScale PrefixPrefix

101033 kk kilokilo 1010-3-3 mm millimilli

101066 MM MegaMega 1010-6-6 uu micromicro

101099 GG GigaGiga 1010-9-9 nn nanonano

10101212 TT TeraTera 1010-12-12 pp picopico

10101515 PP PetaPeta 1010-15-15 ff femtofemto

10101818 EE ExaExa 1010-18-18 aa attoatto

10102121 ZZ ZettaZetta 1010-21-21 zz zeptozepto

10102424 YY YottaYotta 1010-24-24 yy yoctoyocto

Page 4: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

Measure of the accuracy and/or precision of a value.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:Examples:

• 3.495kV has 4 sig figs.3.495kV has 4 sig figs.

• 17.63uA has 3 sig figs.17.63uA has 3 sig figs.

• 400m has 1 sig fig. (unless told otherwise).400m has 1 sig fig. (unless told otherwise).

Significant FiguresSignificant Figures

Page 5: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

Round to nearest least significant digit.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 Our output algorithm automatically truncates (ignores) any digits to the right of the last digit output.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:Examples:

• 4.53243 rounds to 4.532 with 4 sig. figs.4.53243 rounds to 4.532 with 4 sig. figs.

• 4.53243 + 0.0005 = 4.532 | 93 (only output 4 digits)4.53243 + 0.0005 = 4.532 | 93 (only output 4 digits)

• 2.38954 rounds to 2.39 with 3 sig figs.2.38954 rounds to 2.39 with 3 sig figs.

• 2.38954 + 0.005 = 2.39 | 454 (only output 3 digits)2.38954 + 0.005 = 2.39 | 454 (only output 3 digits)

RoundingRounding

Page 6: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

In scientific notation, the value v can be expressed using a mantissa (m) In scientific notation, the value v can be expressed using a mantissa (m) and an exponent (e) as follows:and an exponent (e) as follows:

v = m x 10v = m x 10ee

This value is normalized if m has exactly one non-zero digit to the left of This value is normalized if m has exactly one non-zero digit to the left of the decimal point, i.e, if:the decimal point, i.e, if:

1.0 <= m < 10.01.0 <= m < 10.0

Ignoring significant of leading 1 (for now), 0.5 sig fig is then:Ignoring significant of leading 1 (for now), 0.5 sig fig is then:

hsf = 5 x 10hsf = 5 x 10-N-N (hsf - “hemi-sig fig) (hsf - “hemi-sig fig)

If m has a leading 1, then hsf is another factor of ten smaller:If m has a leading 1, then hsf is another factor of ten smaller:

hsf = 0.5 x 10hsf = 0.5 x 10-N-N

Rounding Normalized ValuesRounding Normalized Values

Page 7: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

1) TASK: Output negative sign and take absolute value.1) TASK: Output negative sign and take absolute value.

2) TASK: Determine the mantissa and the exponent.2) TASK: Determine the mantissa and the exponent.

3) TASK: Add 0.5 Sig Fig to Mantissa3) TASK: Add 0.5 Sig Fig to Mantissa

4) TASK: Scale mantissa so that exponent is divisible by 3.4) TASK: Scale mantissa so that exponent is divisible by 3.

5) TASK: Output mantissa to N sig figs.5) TASK: Output mantissa to N sig figs.

6) TASK: Output prefix based on exponent.6) TASK: Output prefix based on exponent.

7) TASK: Output units.7) TASK: Output units.

8) TASK: Return number of characters printed.8) TASK: Return number of characters printed.

Top Level DecompositionTop Level Decomposition

Page 8: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

v = -0.00001846774 to 4 sig figsv = -0.00001846774 to 4 sig figs

1) TASK: Output negative sign and take absolute value.1) TASK: Output negative sign and take absolute value.

OUTPUT: ‘-’OUTPUT: ‘-’

v = 0.00001846774v = 0.00001846774

2) TASK: Determine the mantissa and the exponent.2) TASK: Determine the mantissa and the exponent.

m = 1.846774m = 1.846774

e = -5e = -5

3) TASK: Add 0.5 Sig Fig to Mantissa3) TASK: Add 0.5 Sig Fig to Mantissa

hsf = 5 x 10hsf = 5 x 10-4-4 = 0.0005 = 0.0005

hsf = hsf/10 = 0.00005 (since m < 2)hsf = hsf/10 = 0.00005 (since m < 2)

m = m + hsf = 1.846774 + 0.00005 = 1.846824m = m + hsf = 1.846774 + 0.00005 = 1.846824

Hand ExampleHand Example

Page 9: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

4) TASK: Scale mantissa so that exponent is divisible by 3.4) TASK: Scale mantissa so that exponent is divisible by 3.

e = -4 not divisible by 3. e = -4 not divisible by 3.

Multiply mantissa by 10 and decrement exponent until it is.Multiply mantissa by 10 and decrement exponent until it is.

m = 18.46824m = 18.46824

e = -3e = -3

5) TASK: Output mantissa to N sig figs.5) TASK: Output mantissa to N sig figs.

Output m to (N+1 digits since leading digit was a 1)Output m to (N+1 digits since leading digit was a 1)

OUTPUT: 18.468OUTPUT: 18.468

6) TASK: Output prefix based on exponent.6) TASK: Output prefix based on exponent.

OUTPUT: mOUTPUT: m

7) TASK: Output units.7) TASK: Output units.

Hand Example (cont’d)Hand Example (cont’d)

Page 10: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

int PutV_Eng(double v, int sigfigs, char *units)int PutV_Eng(double v, int sigfigs, char *units){{

int i, c, e;int i, c, e;double m, hsf;double m, hsf;

/* TASK 1 - Handle negative values *//* TASK 1 - Handle negative values */if (n < 0.0)if (n < 0.0){{

PutC(‘-’);PutC(‘-’);return 1 + PutV_Eng(-v, sigfigs, units);return 1 + PutV_Eng(-v, sigfigs, units);

}}

PutV_Eng() Task 1PutV_Eng() Task 1

Page 11: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

/* TASK 2 - Determine mantissa and exponent *//* TASK 2 - Determine mantissa and exponent */m = 0.0; e = 0;m = 0.0; e = 0;if (v != 0.0)if (v != 0.0){{

while (v >= 10.0)while (v >= 10.0){{

v /= 10.0;v /= 10.0;e++;e++;

}}while (v < 1.0)while (v < 1.0){{

v *= 10.0;v *= 10.0;e--;e--;

}}}}

PutV_Eng() Task 2PutV_Eng() Task 2

Page 12: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

/* TASK 3 - Add 0.5 sig fig *//* TASK 3 - Add 0.5 sig fig */hsf = (m < 2.0)? 0.5 : 5.0;hsf = (m < 2.0)? 0.5 : 5.0;for (i = 0; i < sigfigs; i++)for (i = 0; i < sigfigs; i++)

hsf /= 10.0;hsf /= 10.0;

PutV_Eng() Task 3PutV_Eng() Task 3

Page 13: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

/* TASK 4 - Make exponent divisible by 3 *//* TASK 4 - Make exponent divisible by 3 */while (e%3)while (e%3){{

m *= 10.0;m *= 10.0;e--;e--;

}}

PutV_Eng() Task 4PutV_Eng() Task 4

Page 14: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

/* TASK 5 - Output Mantissa *//* TASK 5 - Output Mantissa */c = PutV_lfN(m, sigfigs + ((m<2.0)? 1 : 0) );c = PutV_lfN(m, sigfigs + ((m<2.0)? 1 : 0) );

/* /* The PutV_lfN() function is basicallyThe PutV_lfN() function is basically the PutV_lf() function except that itthe 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 5PutV_Eng() Task 5

Page 15: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

/* TASK 6 - Output Prefix *//* TASK 6 - Output Prefix */switch(e)switch(e){{

case -24: PutC(‘y’); c++; break;case -24: PutC(‘y’); c++; break;case -21: PutC(‘z’); c++; break;case -21: PutC(‘z’); c++; break;/* ... *//* ... */case -3: PutC(‘m’); c++; break;case -3: PutC(‘m’); c++; break;case 0: break;case 0: break;case 3: PutC(‘k’); c++; break;case 3: PutC(‘k’); c++; break;/* ... *//* ... */case 21: PutC(‘Z’); c++; break;case 21: PutC(‘Z’); c++; break;case 24: PutC(‘Y’); c++; break;case 24: PutC(‘Y’); c++; break;default: PutC(‘e’); c += 1 + PutV_i(e);default: PutC(‘e’); c += 1 + PutV_i(e);

}}

PutV_Eng() Task 6PutV_Eng() Task 6

Page 16: Engineering Notation: Similar to scientific notation. Similar to scientific notation. Exponent is evenly divisible by 3 Exponent is evenly divisible by.

/* TASK 7 - Output Units *//* TASK 7 - Output Units */c += PutS(units);c += PutS(units);

/* TASK 8 - Return number of characters *//* TASK 8 - Return number of characters */return c;return c;

}}

PutV_Eng() Task 7 / 8PutV_Eng() Task 7 / 8