Skip to content

float.h is missing mandatory C11 fp macros like DBL_DECIMAL_DIG and LDBL_DECIMAL_DIG #26657

@llvmbot

Description

@llvmbot
Bugzilla Link 26283
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @hfinkel,@itaraban

Extended Description

Hi, using Clang 3.8 from the Ubuntu ppa I found that float.h does not define some mandatory C11 floating point constants (as per N1570 draft: 5.2.4.2.2p11).

Steps to reproduce: run this simple diagnostic snippet, where Clang fails with "error: use of undeclared identifier 'LDBL_DECIMAL_DIG'", despite the proper include.

#include <stdio.h>
#include <float.h>
int main(void) {
long double x=0.3L;
printf("v=%s; x=%.*Lg\n",VERSION,LDBL_DECIMAL_DIG,x);
return 0;}

Expected: the value is to be printed with the right decimal places, as defined by the C11 spec.

I have checked that at least DBL_DECIMAL_DIG and LDBL_DECIMAL_DIG are not defined on /usr/lib/llvm-3.8/lib/clang/3.8.0/include/float.h, but internal versions with underscores (like LDBL_DECIMAL_DIG) seem to exist elsewhere, but are not exposed in a standard compliant way. I can't say if the underscored versions are "correct" in that they evaluate to the proper value for all target architectures.

All versions of Clang ought to be affected, but only 3.6 and 3.8 were tested. A possibly (vaguely) relevant mailing list post exists: http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20150209/123212.html

GCC/glibc work correctly as expected since at least 4.8.4, but possibly sooner.

No other fp macros were tested, but the above ML post suggests that build tests that check for them are not universally available, so more macros might be missing.

Output of: clang-3.8 --version
Ubuntu clang version 3.8.0-svn257311-1~exp1 (trunk) (based on LLVM 3.8.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:headersHeaders provided by Clang, e.g. for intrinsics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions