Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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.
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.
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.
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.
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.
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.
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 |
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.
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.
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.
<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.