Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeContact

The text of a manual · part 38 of 39

Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual: Appendix E - Using Floating-Point Numbers

Pages 319 to 326 of 337, from Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual

The original document is the PDF (4.4 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the GE Fanuc IC692CPU211D / IC692MDR541C, Fanuc IC692CPU211D / IC692MDR541C, GE IC692CPU211D / IC692MDR541C and GE Fanuc IC693CPU311X

Page 319

Appendix Using Floating-Point Numbers

E There are a few considerations you need to understand when using floating-point numbers. The first section discusses these general considerations. Refer to page E-5 and following for instructions on entering and displaying floating-point numbers.

Note Floating-point capabilities are only supported on the 35x and 36x series CPUs Release 9.00 or later, and on all releases of CPU352 and 37x series.

Floating-Point Numbers The programming software provides the ability to edit, display, store, and retrieve numbers with real values. Some functions operate on floating-point numbers. However, to use floating-point numbers with the programming software, you must have a 35x, 36x or 37x series CPU (see Note above). Floating-point numbers are represented in decimal scientific notation, with a display of six significant digits.

Note In this manual, the terms “floating-point” and “real” are used interchangeably to describe the floating-point number display/entry feature of the programming software. The following format is used. For numbers in the range 9999999 to .0001, the display has no exponent and up to six or seven significant digits. For example: Entered

Displayed

Description

.000123456789

+.0001234567

Ten digits, six or seven significant.

–12.345e-2

–.1234500

Seven digits, six or seven significant.

1234

+1234.000

Seven digits, six or seven significant.

Outside the range listed above, only six significant digits are displayed and the display has the following form: +1.23456E+12

GFK-0467M

E-1

Page 320

E

Real Number Terminology A real number is stored in a 32-bit double word register. The following discusses the terms used for the parts of a real number.

Mantissa

Exponent Indicator

-1.23456E+12 Sign

Radix

Exponent Value

Exponent Sign

Sign – Either plus or minus. Stored in the most significant bit (bit 32) of the double word. A one in bit 32 indicates a negative sign. A zero in bit 32 indicates a positive sign. Radix – A period (dot) symbol that separates the whole number portion from the fractional number portion of the mantissa. For decimal numbers, the radix is commonly called the decimal point. Exponent – (Also called a “Characteristic”). It is stored in 8 bits, in bit positions 31 through 24 of the 32-bit double word. The exponent may have values in the range of +127 to –126; however, the exponent is always stored as a positive number because the CPU automatically adds 127 to its value before storing it. Mantissa – (Also called a Significand”). The basic number without the sign and exponent. It is stored in 23 bits, in bit positions 23 through 1 of the 32-bit word. Precision – Related to the number of significant digits that can be stored. Since a double integer register uses 31 bits to store a number (bit 32 is used for the sign), it can potentially store numbers with greater precision than a real (floating-point) register, which only uses 23 bits to store a number’s mantissa.

E-2

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M

Page 321

E

Internal Format of Floating-Point Numbers Floating-point numbers are stored in single precision IEEE-standard format. This format requires 32 bits, which translates to two adjacent 16-bit PLC registers. The encoding of the bits is diagrammed below.

Bits 17-32 32 31

Bits 1-16

24 23

1

17 16 23-bit mantissa

8-bit exponent 1-bit sign (Bit 32)

Register use by a single floating-point number is diagrammed below. In this diagram, if the floating-point number occupies registers %R0005 and %R0006, for example, %R0005 is the least significant register and %R0006 is the most significant register.

Least Significant Register Bits 1-16 16

1 Least Significant Bit: Bit 1 Most Significant Bit: Bit 16

Most Significant Register Bits 17-32 32

17 Least Significant Bit: Bit 17 Most Significant Bit: Bit 32

GFK-0467M

Appendix E Using Floating-Point Numbers

E-3

Page 322

E

Values of Floating-Point Numbers Use the following table to calculate the value of a floating-point number from the binary number stored in two registers. Exponent (e)

Mantissa (f)

Value of Floating Point Number

255

Non-zero

255

0

0 < e < 255

Any value

–1s * 2e–127 * 1.f

0

Non-zero

–1s * 2–126 * 0.f

0

0

Not a valid number (NaN).

–1s * ∞

0 f = the mantissa. The mantissa is a binary fraction. e = the exponent. The exponent is an integer E such that E+127 is the power of 2 by which the mantissa must be multiplied to yield the floating-point value. s = the sign bit. * = the multiplication operator.

For example, consider the floating-point number 12.5. The IEEE floating-point binary representation of the number is: 01000001 01001000 00000000 00000000 or 41480000 hex. The most significant bit (the sign bit) is zero (s=0). The next eight most significant bits are 10000010, or 130 decimal (e=130). The mantissa is stored as a decimal binary number with the decimal point preceding the most significant of the 23 bits. Thus, the most significant bit in the mantissa is a multiple of 2–1, the next most significant bit is a multiple of 2–2, and so on to the least significant bit, which is a multiple of 2–23. The final 23 bits (the mantissa) are: 1001000 00000000 00000000

The value of the mantissa, then, is .5625 (that is, 2–1 + 2–4). Since e > 0 and e < 255, we use the third formula in the table above: number = –1s * 2e–127 * 1.f = –10 * 2130–127 * 1.5625 = 1 * 23 * 1.5625 = 8 * 1.5625 = 12.5

Thus, you can see that the above binary representation is correct. The range of numbers that can be stored in this format is from ± 1.401298E–45 to ± 3.402823E+38 and the number zero.

E-4

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M

Page 323

E

Entering and Displaying Floating-Point Numbers In the mantissa, up to six or seven significant digits of precision may be entered and stored; however, the programming software will display only the first six of these digits. The mantissa may be preceded by a positive or negative sign. If no sign is entered, the floating-point number is assumed to be positive. If an exponent is entered, it must be preceded by the letter E or e, and the mantissa must contain a decimal point to avoid mistaking it for a hexadecimal number. The exponent may be preceded by a sign; but, if none is provided, it is assumed to be positive. If no exponent is entered, it is assumed to be zero. No spaces are allowed in a floating-point number. To provide ease-of-use, several formats are accepted in both command-line and field data entry. These formats include an integer, a decimal number, or a decimal number followed by an exponent. These numbers are converted to a standard form for display once the user has entered the data and pressed the Enter key. Examples of valid floating-point number entries and their normalized display are shown below. Entered

Displayed in Logicmaster

250

+250.0000

+4

+4.000000

–2383019

–2383019.

34.

+34.00000

–.0036209

–.003620900

12.E+9

+1.20000E+10

–.0004E–11

–4.00000E–15

731.0388

+731.0388

99.20003e–29

+9.92000E–28

Examples of invalid or incorrect floating-point number entries are shown below. Incorrect Entry

GFK-0467M

Explanation/Result

–433E23

Missing decimal point. LM90 displays message “Bad numeric value.”

10e-19

Missing decimal point. LM90 displays message “Bad numeric value.”

1 0.e19

There is a space between the 1 and the 0 in the mantissa. Real numbers must be entered without spaces between digits or characters. Logicmaster recognizes this entry as the incorrect value +1.000000.

4.1e 19

There is a space between the e and the 19 in the exponent. Real numbers must be entered without spaces between digits or characters. Logicmaster recognizes this entry as the incorrect value +4.100000.

Appendix E Using Floating-Point Numbers

E-5

Page 324

E

Errors in Floating-Point Numbers and Operations Positive and Negative Infinity On a 352 or 374 CPU, overflow occurs when a number greater than 3.402823E+38 or less than -3.402823E+38 is generated by a REAL function. On all other 90-30 models that support floating point operations, the range is greater than 216 or less than –216. When your number exceeds the range, the ok output of the function is set OFF, and the result is set to positive infinity (for a number greater than 3.402823E+38 on a 352 or 374 CPU or 216 on all other models) or negative infinity (for a number less than –3.402823E+38 or –216 on all other models). You can determine where this occurs by testing the sense of the ok output. Mnemonic

Ladder Screen Value

Reference Table Value (Hex)

Description

POS_INF

+OVERFLOW

7F80 0000

IEEE positive infinity representation in hex.

NEG_INF

-OVERFLOW

FF80 0000

IEEE negative infinity representation in hex.

Note If you are using software floating point (all models capable of floating point operations except the 352 or 374 CPU), numbers are rounded to zero (0) at ±1.175494E–38. If the infinities produced by overflow are used as operands to other REAL functions, they may cause an undefined result. This undefined result is referred to as an NaN (Not a Number). For example, the result of adding positive infinity to negative infinity is undefined. When the ADD_REAL function is invoked with positive infinity and negative infinity as its operands, it produces an NaN for its result.

Not a Number (NaN) A Not a Number is an undefined number such as the result of dividing zero by zero. Positive and Negative Infinities are not considered to be NaNs. The following sections will help you identify when an NaN result has been obtained.

E-6

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M

Page 325

E NaN Codes for 352 or 374 CPU On a 352 or 374 CPU, each REAL function capable of producing an NaN produces a specialized NaN code that identifies the function and can be read in the applicable Reference Table. The indication on the Logicmaster ladder logic screen will be the unsigned term “OVERFLOW.” (If the term “OVERFLOW” is preceded by a plus or minus sign, it indicates a positive or negative infinity.) Not a Number (NaN) Codes for the 352 and 374 CPU Mnemonic

Reference Table Value (Hex)

Description

NaN_ADD.

7F81 FFFF

Real addition error value in hex.

NaN_SUB

7F81 FFFF

Real subtraction error value in hex.

NaN_MUL

7F82 FFFF

Real multiplication error value in hex.

NaN_DIV

7F83 FFFF

Real division error value in hex.

NaN_SQRT

7F84 FFFF

Real square root error value in hex.

NaN_LOG

7F85 FFFF

Real logarithm error value in hex.

NaN_POW0

7F86 FFFF

Real exponent error value in hex.

NaN_SIN

7F87 FFFF

Real sine error value in hex.

NaN_COS

7F88 FFFF

Real cosine error value in hex.

NaN_TAN

7F89 FFFF

Real tangent error value in hex.

NaN_ASIN

7F8A FFFF

Real inverse sine error value in hex.

NaN_ACOS

7F8B FFFF

Real inverse cosine error value in hex.

NaN_BCD

7F8C FFFF

BCD-4 to real error.

REAL_INDEF

FFC0 0000

Real indefinite, divide 0 by 0 error.

NaN Code for 35x, 36x, and 37x CPUs (excluding 352 CPU) All Series 90-30 CPUs that support firmware-based floating point operations (which excludes the 352 CPU, which is hardware-based) produce only one NaN output: FFFF FFFF. The indication on the Logicmaster ladder logic screen will be the unsigned term “OVERFLOW.”

Not a Number (NaN) Type for 35x, 36x, and 37xCPUs (Excluding 352 CPU)

GFK-0467M

Mnemonic

Reference Table Value (Hex)

Description

NaN_SW

FFFF FFFF

Software Floating Point code for all NaNs

Appendix E Using Floating-Point Numbers

E-7

Page 326

E

Propagation and Power Flow for NaN and Infinity Numbers When an NaN result is fed into another function, it passes through to the result. For example, if an NaN_ADD is the first operand to the SUB_REAL function, the result of the SUB_REAL is NaN_ADD. If both operands to a function are NaNs, the first operand will pass through. Because of this feature of propagating NaNs through functions, you can identify the function where the NaN originated.

Note For NaN, the ok output is OFF (not energized). The following table explains when power is or is not passed when dealing with numbers viewed as or equal to infinity for binary operations such as Add, Multiply, etc. As shown previously, outputs that exceed the positive or negative limits are viewed as POS_INF or NEG_INF respectively. Table E-1. General Case of Power Flow for Floating-Point Math Operations Operation

E-8

Input 1

Input 2

Output

Power Flow

All

Number

Number

Positive or Negative Infinity

No

All Except Division

Infinity

Number

Infinity

Yes

All

Number

Infinity

Infinity

Yes

Division

Infinity

Number

Infinity

No

All

Number

Number

NaN

No

Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002

GFK-0467M