MainframeMaster

Floating-Point Formats

In DFSORT, floating-point data is stored in a binary format that represents a number using a sign, an exponent, and a mantissa (or fraction)—not as a string of decimal digits like PD or ZD. The FL format tells DFSORT to interpret the sort key as a floating-point number and compare numeric value. On the mainframe, two common families are IBM hexadecimal floating-point (used by COBOL COMP-1 and COMP-2) and IEEE binary floating-point. Support for FL and the exact byte layout (4 bytes single-precision, 8 bytes double-precision) is product-dependent. This page explains what floating-point formats are, how FL fits in, the difference between IBM hex float and IEEE, when to use FL versus PD/ZD/FS, and how to handle special values like NaN and infinity.

Data Types & Formats
Progress0 of 0 lessons

What Is Floating-Point Storage?

A floating-point value is stored as a combination of sign (positive or negative), exponent (power of the base), and mantissa (significant digits). The same bit pattern is not a simple integer or a decimal string—so comparing the bytes as character (CH) or as packed/zoned decimal (PD/ZD) does not give correct numeric order. DFSORT FL is the format that says: "interpret these bytes as a floating-point number and compare by numeric value." The exact interpretation depends on which floating-point format the bytes use (e.g. IBM hex float vs IEEE) and what your DFSORT product supports.

IBM Hexadecimal Floating-Point

In IBM hexadecimal floating-point, the number is represented in a two-part form: characteristic (exponent) and fraction, with the sign in bit position 0. IBM documentation gives the example: +247 in halfword form becomes X'42F70000...' (binary: 0 1000010 111101110000000... — sign, characteristic, fraction). Negative -247 is the same with the sign bit set to 1 (X'C2F70000...'). This format is commonly used by COBOL COMP-1 (typically 4 bytes) and COMP-2 (typically 8 bytes). When your sort key is a COMP-1 or COMP-2 field, you need to use a format that interprets this layout—typically FL with length 4 or 8, if your DFSORT product supports IBM hex float.

IEEE Binary Floating-Point

IEEE binary floating-point (IEEE 754) uses a different layout: sign bit, exponent, and mantissa in a defined order. Single-precision is 4 bytes; double-precision is 8 bytes. Many non-mainframe systems use IEEE. If your data is generated or exchanged with systems that use IEEE float, the byte layout in the record may be IEEE. DFSORT support for IEEE (and whether FL means IBM or IEEE or is selectable) is product-dependent. Check your DFSORT manual to see which floating-point formats FL supports and how to specify length and format.

Single- vs Double-Precision

Single-precision floating-point usually occupies 4 bytes and has less range and precision than double-precision. Double-precision usually occupies 8 bytes and can represent more digits and a wider range. In COBOL, COMP-1 is typically single-precision and COMP-2 is typically double-precision. When you specify FL in SORT FIELDS, you must give the length in bytes (4 or 8) that matches the actual storage. Using the wrong length misinterprets the key and can cause wrong order or unpredictable behavior.

Typical floating-point lengths
Length (bytes)Common nameCOBOL example
4Single-precisionCOMP-1
8Double-precisionCOMP-2

FL in SORT FIELDS

Use FL in SORT FIELDS when the key is stored in a floating-point format that your product supports:

text
1
SORT FIELDS=(start,length,FL,direction)
  • start — Starting position of the float field (1-based).
  • length — 4 or 8 (bytes), matching single- or double-precision.
  • FL — Format: floating-point. Product determines IBM vs IEEE and exact comparison rules.
  • direction — A for ascending, D for descending.

Example: 8-byte double-precision float at position 20, ascending:

text
1
SORT FIELDS=(20,8,FL,A)

Example: primary key character 1–10, secondary key 4-byte float at 11–14, ascending:

text
1
SORT FIELDS=(1,10,CH,A,11,4,FL,A)

FL vs Other Formats

Do not use the wrong format for float data
FormatEffect if used on float data
CHByte-by-byte comparison; order is not numeric. Wrong sort order.
PDBytes interpreted as packed decimal; wrong value and order.
ZDBytes interpreted as zoned decimal; wrong value and order.
FI/BIInteger interpretation; wrong for non-integer floats and scale.
FLCorrect: numeric float comparison (when product supports the data format).

Conversely, do not use FL for packed decimal (use PD), zoned decimal (use ZD), or display numeric with floating sign (use FS). FL is only for binary floating-point storage.

FS vs FL: Do Not Confuse

FS (or CSF) in DFSORT means signed numeric with optional leading floating sign—a display format where the sign character can appear in variable position (e.g. " +34", "-003"). It is for character/display data from FORTRAN, PL/I, or COBOL PIC ++9. FL means floating-point—binary representation with sign, exponent, and mantissa (e.g. COMP-1, COMP-2). The names are similar but the formats are completely different. Use FS for display numbers with floating sign; use FL for binary float keys.

Special Values: NaN, Zero, Infinity

Floating-point standards define special bit patterns: NaN (Not a Number), negative zero (-0) and positive zero (+0), and positive and negative infinity. Different DFSORT products may sort these in different positions—for example, NaN might be ordered last, or -infinity first in ascending order. If your data can contain these values, consult your DFSORT documentation for how FL treats them so you know where they will appear in the output.

When to Use FL

  • Sort key is COBOL COMP-1 or COMP-2 (confirm product supports the format and length).
  • Sort key is application data stored in IBM hex float or IEEE float that your DFSORT product supports.
  • You need correct numeric order for real numbers (with decimal point); the key is not packed, zoned, or display format.

When Not to Use FL

  • Packed decimal (COMP-3) — Use PD.
  • Zoned decimal (DISPLAY) — Use ZD.
  • Display numeric with floating sign (PIC ++9, etc.) — Use FS, not FL.
  • Character or alphanumeric keys — Use CH.

Explain It Like I'm Five

Some numbers have a decimal point, like 3.14 or 0.001. The computer can store them in a special "science" way: a little bit for plus/minus, a little bit for how big the number is (the exponent), and a little bit for the digits (the mantissa). That way it can handle very big and very small numbers. When we sort, we have to tell the sort program: "this part of the record is that kind of number," so it compares 2.5 and 10.0 correctly. That's FL. If we told it "these are just letters" (CH) or "these are packed digits" (PD), it would get the order wrong. So we use FL only when the key is really stored in that special float form.

Exercises

  1. Your record has a COBOL COMP-2 field at position 40 (8 bytes). Write a SORT FIELDS statement to sort by this key ascending. What do you need to confirm with your DFSORT product?
  2. Why does comparing a float field with CH produce wrong sort order? Explain in one or two sentences.
  3. What is the difference between FS (floating sign) and FL (floating-point)? Give an example of data that would use each.
  4. If your data might contain NaN or infinity, what should you do before relying on FL sort order?

Quiz

Test Your Knowledge

1. What is the main difference between IBM hexadecimal floating-point and IEEE binary floating-point in DFSORT?

  • They are the same
  • IBM hex float uses a characteristic-and-fraction layout with sign in bit 0; IEEE uses sign, exponent, mantissa in a different bit layout. DFSORT FL support depends on product.
  • IEEE is only for Windows
  • IBM format is 8 bytes only

2. Which COBOL data types typically use floating-point storage that might require FL in SORT FIELDS?

  • COMP-3 only
  • COMP and COMP-4 only
  • COMP-1 (single-precision) and COMP-2 (double-precision); storage is often IBM hex float
  • DISPLAY only

3. Why must you not use CH for a floating-point sort key?

  • CH is slower
  • Byte-by-byte character comparison does not match numeric order for floating-point bit patterns; the sort order would be wrong
  • CH is only for integers
  • CH requires 8 bytes

4. What are common lengths for FL in DFSORT?

  • 1 and 2 bytes only
  • 2 and 4 bytes only
  • Typically 4 bytes (single-precision) or 8 bytes (double-precision); exact support is product-dependent
  • Always 8 bytes

5. What special floating-point values can affect sort order?

  • None
  • Only zero
  • NaN (Not a Number), negative zero (+0 vs -0), and positive/negative infinity; different products may order them differently
  • Only infinity