Bug 191754 - [headers] long math functions (powl, etc) are not declared properly in math.h
Summary: [headers] long math functions (powl, etc) are not declared properly in math.h
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-08 21:23 UTC by Enji Cooper
Modified: 2014-08-11 20:26 UTC (History)
3 users (show)

See Also:


Attachments
patch for math.h.diff (1.83 KB, patch)
2014-08-06 23:25 UTC, Steve Kargl
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper freebsd_committer freebsd_triage 2014-07-08 21:23:26 UTC
POSIX claims that powl(3) should be defined via math.h/libm ( http://pubs.opengroup.org/onlinepubs/9699919799/functions/pow.html) with std=c99, but unfortunately this appears to be broken on FreeBSD 10-STABLE/11-CURRENT. If I remove the "#if _DECLARE_C99_LDBL_MATH" guard from math.h, things compile more cleanly (it just emits a warning about loss in precision because of the imprecise functions). This guard should probably have a !defined(__cplusplus) check added to it.

Before:

% clang -std=iso9899:1999 -lm -o /root/powl_undeclared /root/powl_undeclared.c
/root/powl_undeclared.c:9:41: warning: implicitly declaring library function 'powl' with type 'long double (long double, long double)'
        printf("powl(%Lf, %Lf) = %Lf\n", a, b, powl(a, b));
                                               ^
/root/powl_undeclared.c:9:41: note: please include the header <math.h> or explicitly provide a declaration for 'powl'
1 warning generated.
/tmp/powl_undeclared-252fa5.o: In function `main':
/root/powl_undeclared.c:(.text+0x4e): warning: powl has lower than advertised precision
% gcc -std=c99 -lm -o /root/powl_undeclared /root/powl_undeclared.c
/root/powl_undeclared.c: In function 'main':
/root/powl_undeclared.c:9: warning: implicit declaration of function 'powl'
/root/powl_undeclared.c:9: warning: incompatible implicit declaration of built-in function 'powl'
/tmp//ccSJGxdD.o: In function `main':
powl_undeclared.c:(.text+0x54): warning: powl has lower than advertised precision
% gcc46 -std=c99 -lm -o /root/powl_undeclared /root/powl_undeclared.c
/root/powl_undeclared.c: In function 'main':
/root/powl_undeclared.c:9:2: warning: implicit declaration of function 'powl' [-Wimplicit-function-declaration]
/root/powl_undeclared.c:9:41: warning: incompatible implicit declaration of built-in function 'powl' [enabled by default]
/tmp//ccmC02s8.o: In function `main':
powl_undeclared.c:(.text+0x54): warning: powl has lower than advertised precision
% gcc -std=iso9899:1999 -lm -o /root/powl_undeclared /root/powl_undeclared.c
/root/powl_undeclared.c: In function 'main':
/root/powl_undeclared.c:9: warning: implicit declaration of function 'powl'
/root/powl_undeclared.c:9: warning: incompatible implicit declaration of built-in function 'powl'
/tmp//ccGtRDWg.o: In function `main':
powl_undeclared.c:(.text+0x54): warning: powl has lower than advertised precision
% gcc46 -std=iso9899:1999 -lm -o /root/powl_undeclared /root/powl_undeclared.c
/root/powl_undeclared.c: In function 'main':
/root/powl_undeclared.c:9:2: warning: implicit declaration of function 'powl' [-Wimplicit-function-declaration]
/root/powl_undeclared.c:9:41: warning: incompatible implicit declaration of built-in function 'powl' [enabled by default]
/tmp//ccjUVEX8.o: In function `main':
powl_undeclared.c:(.text+0x54): warning: powl has lower than advertised precision

After:

% gcc46 -std=iso9899:1999 -lm -o /root/powl_undeclared /root/powl_undeclared.c
/tmp//ccMsjZpJ.o: In function `main':
powl_undeclared.c:(.text+0x54): warning: powl has lower than advertised precision
% clang -std=iso9899:1999 -lm -o /root/powl_undeclared /root/powl_undeclared.c
/tmp/powl_undeclared-ed9797.o: In function `main':
/root/powl_undeclared.c:(.text+0x4e): warning: powl has lower than advertised precision
% gcc -std=iso9899:1999 -lm -o /root/powl_undeclared /root/powl_undeclared.c
/tmp//ccFvfEeJ.o: In function `main':
powl_undeclared.c:(.text+0x54): warning: powl has lower than advertised precision
Comment 1 Steve Kargl freebsd_committer freebsd_triage 2014-08-06 23:25:49 UTC
Created attachment 145432 [details]
patch for math.h.diff
Comment 2 Steve Kargl freebsd_committer freebsd_triage 2014-08-07 00:03:30 UTC
This appears to be a question about compliance to the C99 standard.
Change the component accordingly.
Comment 3 Enji Cooper freebsd_committer freebsd_triage 2014-08-08 06:00:16 UTC
(In reply to Steve Kargl from comment #2)
> This appears to be a question about compliance to the C99 standard.
> Change the component accordingly.

LGTM!
Comment 4 commit-hook freebsd_committer freebsd_triage 2014-08-09 15:54:25 UTC
A commit references this bug:

Author: kargl
Date: Sat Aug  9 15:53:41 UTC 2014
New revision: 269758
URL: http://svnweb.freebsd.org/changeset/base/269758

Log:
  When r255294 was committed, it exposed the symbols lgammal, powl,
  and tgammal in libm.  These functions are part of ISO/IEC 9899:1999
  and their prototypes should have been moved into the appropriate
  __ISO_C_VISIBLE >= 1999 section.  After moving the prototypes,
  remnants of r236148 can be removed.

  PR:		standards/191754
  Reviewed by:	bde

Changes:
  head/lib/msun/src/math.h
Comment 5 Steve Kargl freebsd_committer freebsd_triage 2014-08-09 15:56:07 UTC
Thanks for the PR.
Comment 6 Enji Cooper freebsd_committer freebsd_triage 2014-08-11 20:26:41 UTC
(In reply to Steve Kargl from comment #5)
> Thanks for the PR.

Thanks for the fix :)... Should this be MFCed?