Main Content

AUTOSAR C++14 Rule A0-4-2

Type long double shall not be used

Description

Rule Definition

Type long double shall not be used.

Rationale

The size of long double is implementation-dependent and reduces the portability of your code across compilers. Compilers can implement long double as a synonym for double or an 80-bit extended precision type or 128-bit quadruple precision type that are more precise than double.

Instead, for multiple precision arithmetic that requires types more precise than double, use libraries that support multiple precision arithmetic with well-defined data types.

Polyspace Implementation

The rule checker flags all uses of the long double keyword.

If you do not want to fix the issue, add a comment justifying the result. See:

Troubleshooting

If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

void func() {
  float f{0.1F};  //Compliant
  double D(0.1);  //Compliant
  long double LD(0.1L);  //Noncompliant
}

The use of long double violates this rule.

Check Information

Group: Language independent issues
Category: Required, Automated

Version History

Introduced in R2019a