CAN CSA ISO IEC TS 18661-5-18: A Technical Guide to Decimal Floating-Point Extensions for C

Exploring the Canadian adoption of the ISO/IEC Technical Specification for non-computational decimal floating-point operations in the C programming language

The standard CAN/CSA ISO/IEC TS 18661-5-18 is the Canadian national adoption of the international Technical Specification ISO/IEC TS 18661-5:2016. It defines non-computational operations for decimal floating-point types in the C programming language, extending ISO/IEC 9899 (the C Standard) and complementing IEC 60559 (IEEE 754) and earlier parts of the ISO/IEC TS 18661 series. This article reviews its scope, technical requirements, implementation aspects, and compliance considerations for developers and organizations adopting decimal floating-point arithmetic in C.

1. Scope and Context

CAN/CSA ISO/IEC TS 18661-5-18 focuses exclusively on non-computational operations—that is, operations that do not involve arithmetic computation. These include conversions between decimal floating-point formats and character strings, conversions between decimal and binary floating-point formats, conversions to and from integer types, sign and exponent manipulation, quantum extraction, and classification functions. The standard is part of a five-part Technical Specification series that, together with the C Standard (ISO/IEC 9899), provides a complete decimal floating-point environment.

The standard applies to the decimal floating-point types _Decimal32, _Decimal64, and _Decimal128. Its primary use cases are financial, commercial, and user-facing applications where binary rounding errors are unacceptable.

Tip: Decimal floating-point arithmetic is fundamental to financial applications because it can represent decimal fractions (e.g., 0.10) exactly, whereas binary floating-point often cannot. The non-computational operations specified in this TS are the bridge between decimal data and input/output.

As a Canadian standards adoption, CAN/CSA ISO/IEC TS 18661-5-18 serves as a normative reference for compliance in Canada. It is identical to the international Technical Specification except for Canadian specificities such as front matter and bilingual (English/French) availability.

2. Technical Requirements

2.1 Classification and Exceptions

The standard specifies functions for interrogating the properties of decimal floating-point numbers: fpclassify, isfinite, isinf, isnan, isnormal, and signbit. These functions are overloaded to handle each decimal floating-point type.

2.2 String and Format Conversions

String conversion functions enable parsing and formatting of decimal values. The strtod32, strtod64, and strtod128 functions convert character strings to decimal floating-point numbers. Their counterparts strfromd32, strfromd64, and strfromd128 perform reverse conversion with configurable format (fixed, scientific, general, hex) and precision.

2.3 Inter-Format Conversions

The standard defines conversions between decimal types themselves, between decimal and binary floating-point, and between decimal and integer types. For example, d32tobinary converts a _Decimal32 value to an equivalent binary float, whereas binarytodecimal64 converts a binary float to _Decimal64. Integer conversions follow similar patterns.

2.4 Quantum and Exponent Operations

These include functions to obtain the quantum (quantum), test quantum equality (samequantum), quantize a number (quantize), and manipulate the exponent (scalbn, logb). These operations are essential for careful control of precision and uncertainty in decimal computations.

Function Family Header Purpose Example Functions
Classification <stddecimal.h> Test properties of decimal floats (finite, NaN, normal, etc.) isfinite(d64), isnan(d128)
String I/O <stddecimal.h> Parse decimal floats from strings and format to strings strtod32, strfromd128
Type Conversions <stddecimal.h> Convert between decimal, binary, and integer types d64tobinary, binarytodecimal128
Quantum & Exponent <math.h> / <stddecimal.h> Extract quantum, quantize, manipulate exponent quantize, quantum, scalbn, logb
Sign & Copy <stddecimal.h> Copy sign, absolute value, negate copysignd64, fabsd64

3. Implementation Considerations

Compilers such as GCC and Clang provide experimental or full support for decimal floating-point types as defined by the ISO/IEC TS 18661 series. In GCC, the types _Decimal32, _Decimal64, and _Decimal128 can be used with the -std=c2x flag, and the non-computational functions become accessible via the <stddecimal.h> header. For legacy deployments, the <decimal/decimal.h> header may be available depending on the compiler version.

Warning: Decimal floating-point operations are not bit-for-bit identical to binary floating-point. Developers must be careful when mixing types or relying on rounding behavior. The non-computational functions can help capture and control rounding when converting between formats.

Linking may require an additional library such as -ldecimal or -lgcc (for GCC built-in software decimal support). Implementations must also maintain thread safety and handle rounding direction correctly according to the current rounding mode.

Success: The Canadian adoption aligns with C23, which incorporates decimal floating-point concepts from the TS 18661 series. Code written under CAN/CSA ISO/IEC TS 18661-5-18 will be forward-compatible with C23 and future C standards.

4. Compliance Notes

Conformance to CAN/CSA ISO/IEC TS 18661-5-18 requires implementation of all mandatory functions and features specified in the Technical Specification. The standard is intended to be used in conjunction with the C Standard (ISO/IEC 9899) and the other parts of ISO/IEC TS 18661. Testing for compliance can be performed using the IEEE 754 decimal test suite, which provides test vectors for all non-computational operations.

In Canada, this standard is recognized as a national standard of Canada (CAN/CSA). Organizations seeking compliance in procurement or regulatory contexts should ensure their software development environment includes a CSA-accredited implementation of the standard.

Important: Non-computational operations do not replace the computational arithmetic defined in ISO/IEC TS 18661-2. For algorithms that require addition, subtraction, multiplication, or division of decimal floats, part 2 must be referenced. Part 5 only covers supporting operations.
Q: What is the difference between CAN/CSA ISO/IEC TS 18661-5-18 and the ISO/IEC TS 18661-5:2016?
A: They are technically identical. The CAN/CSA version adds Canadian front matter and is published as a National Standard of Canada by the Canadian Standards Association. The year 2018 indicates the year of Canadian adoption.
Q: Which header is used to access the functions defined in this standard?
A: The primary header is <stddecimal.h> as specified in the TS. Some compilers may also provide <decimal/decimal.h> for backward compatibility. Always refer to the implementation’s documentation.
Q: Is this standard required for financial software in Canada?
A: While not mandated by law, the CSA adoption ensures that implementations claiming conformance follow rigorous specifications. Financial software that requires exact decimal representation should strongly consider using decimal floating-point as defined by this TS.
Q: How does this standard relate to C23?
A: C23 (ISO/IEC 9899:2024) includes decimal floating-point support largely based on ISO/IEC TS 18661 parts 1-5. Therefore, the non-computational operations from this TS are integrated into the C23 standard library. © 2026 tnlab.org — This article is for educational and technical reference purposes.

📥 Standard Documents Download

🔒
Please wait 10 seconds, the download links will appear after the ad loads

Leave a Reply

Your email address will not be published. Required fields are marked *