Opened 14 years ago

Closed 11 years ago

#7007 closed bug (fixed)

Implement missing <math.h> functions

Reported by: scottmc Owned by: nobody
Priority: normal Milestone: R1/beta1
Component: System/POSIX Version: R1/Development
Keywords: Cc: andreasf
Blocked By: Blocking:
Platform: All

Description

These are present in the math.h header, but not yet implemented: math.h:

lgammal gamma_r gammaf_r

The following issues also need to be adressed in math.h:

  1. Missing definition of float_t and double_t as described at opengroup.org.
  2. Missing declaration of FLT_EVAL_METHOD.
  3. Function "int isgreater(real-floating x, real-floating y);" is never defined or declared in the header.
  4. Function "int isgreaterequal(real-floating x, real-floating y);" is never defined or declared in the header.
  5. Functions "int isless(real-floating x, real-floating y);,

int islessequal(real-floating x, real-floating y);, int islessgreater(real-floating x, real-floating y);" are never defined or declared in the header.

  1. Function "int isunordered(real-floating x, real-floating y);" is never defined or declared in the header.
  2. There is no definition of "MAXFLOAT" constant in the header.
  3. The following optional macros "FP_FAST_FMA, FP_FAST_FMAF, FP_FAST_FMAL" are not defined in the header.
  4. The following macros "FP_ILOGB0, FP_ILOGBNAN, MATH_ERRNO, MATH_ERREXCEPT, math_errhandling" are never defined in the header.

The functions need to provide the requirements as defined at: http://www.opengroup.org/onlinepubs/9699919799/basedefs/math.h.html

This is being worked on by a GCI student. This is for the math.h in headers/posix/math.h

Attachments (7)

math_changes.patch (6.1 KB ) - added by ReidH 14 years ago.
math_changes.2.patch (6.3 KB ) - added by ReidH 14 years ago.
0001-Add-missing-definitions-to-math.h.patch (3.1 KB ) - added by scottmc 12 years ago.
0002-Add-glibc-ilogbl-implemenation.patch (7.0 KB ) - added by scottmc 12 years ago.
0003-Add-s_ldexpl.c-to-x86-jamfile.patch (863 bytes ) - added by scottmc 12 years ago.
0004-Add-s_tanhl.c-to-x86-jamfile.patch (812 bytes ) - added by scottmc 12 years ago.
0005-Add-gamma-f-_r-declarations-and-aliases.patch (2.1 KB ) - added by scottmc 12 years ago.

Download all attachments as: .zip

Change History (22)

by ReidH, 14 years ago

Attachment: math_changes.patch added

comment:1 by ReidH, 14 years ago

patch: 01

comment:2 by ReidH, 14 years ago

I found two headers that seemed to pertain to this ticket. headers/posix/math.h and /system/libroot/posix/glibc/math/math.h.

1, 2, 8 and 9 were added to system/libroot/posix/glibc/math/math.h because there was a whole commented section requesting them.

3, 4, 5 and 6 were already defined as macros in system/libroot/posix/glibc/math/math.h so I made no changes.

This confused me, this ticket says it is for headers/posix/math.h, yet a lot of work seemed like it either needed to be done in, or had already been done in /system/libroot/posix/glibc/math/math.h.

As for gamma_r and gammaf_r, I found their definitions from Sun, where the rest of the definitions apparently came from. And with some slight altering I believed I successfully implemented them in the form of two files (w_gamma_r.c and w_gammaf_r.c) residing in src/system/libroot/posix/glibc/arch/generic.

lgammal seemed to already be implemented, and I saw a page on dev.haiku-os.org that seemed to confirm this.

The only altering made to headers/posix/math.h was the definition of MAXFLOAT.

I don't know if the two headers are in any way linked, or if everything I did in /system/libroot/posix/glibc/math/math.h should have been added to headers/posix/math.h along with redefining all the macros found in /system/libroot/posix/glibc/math/math.h.

Any help is appreciated. -Reid

comment:3 by korli, 14 years ago

headers/posix/math.h is a public header owned by Haiku. src/system/libroot/posix/glibc/math/math.h is a private header from Glibc and is maintained there.

Missing definitions (if they're really missing) should be added to headers/posix/math.h to be used by user applications.

Glibc implementations should actually be used (even if they happen to be from Sun). You should find them at this place: http://sourceware.org/git/?p=glibc.git;a=tree;f=math;h=4d12aaac32cd639876398a5732b26a4fd8c5c08b;hb=14b697f75a5f039a0e3155c62399ee217c0f17dc http://sourceware.org/git/?p=glibc.git;a=tree;f=sysdeps/ieee754/flt-32;h=6a47a4d722f4b99d4226f9df047f695dc7aebe3b;hb=14b697f75a5f039a0e3155c62399ee217c0f17dc http://sourceware.org/git/?p=glibc.git;a=tree;f=sysdeps/ieee754/dbl-64;h=a1ee9700d652ca2d8809172aaab6d8d593802289;hb=14b697f75a5f039a0e3155c62399ee217c0f17dc

Beware w_gamma_r.c and w_gammaf_r.c are only wrappers.

A (very simple) test program for these functions would be appreciated.

by ReidH, 14 years ago

Attachment: math_changes.2.patch added

comment:4 by ReidH, 14 years ago

I undid all of my changes to /system/libroot/posix/glibc/math/math.h and basically did everything the task asked to headers/posix/math.h.

Although everything looks fine to me, I'm sure there is still some work that needs to be done.

Just let me know and i'll do my best.

-Reid

comment:5 by korli, 14 years ago

Thanks.

For GCC4, one should use the builtins functions provided by the compiler: #define isgreater(x, y) builtin_isgreater ((x),(y)) #define isgreaterequal(x, y) builtin_isgreaterequal ((x),(y)) #define isless(x, y) builtin_isless ((x),(y)) #define islessequal(x, y) builtin_islessequal ((x),(y)) #define islessgreater(x, y) builtin_islessgreater ((x),(y)) #define isunordered(x, y) builtin_isunordered ((x),(y))

For GCC2, you should definitely rewrite these definitions, sorry but they look like verbatim copies of glibc math.h. I hope you understand this point.

MAXFLOAT should be defined to the max float value FLT_MAX defined by the compiler (including float.h might be required).

Unless fma() calls are indeed fast, FP_FAST_FMA definitions should be better zero valued. Please add a TODO comment if this needs to be revisited. For FP_ILOGB0 and FP_ILOGBNAN, I'd prefer the *_MAX equivalent definitions.

Defining math_errhandling to 3 is a bit fast. Please add a TODO comment if this needs to be revisited. Also 3 is actually the (MATH_ERRNO | MATH_ERREXCEPT).

w_lgammal.c, w_gamma_r.c and w_gammaf_r.c are to be added to respective arch Jamfiles to be included in the build. gamma* functions seem to be deprecated in posix specifications. We might want to only include those for GCC2.

comment:6 by andreasf, 14 years ago

Cc: andreasf added

comment:7 by scottmc, 14 years ago

@ReidH, If you manage to complete this before the GCI deadline and still want to get the credit for it you can submit your patch(es) here and when they are deemed good then reclaim the task and we can mark it complete, that way you aren't being held up while you have another task open.

comment:8 by scottmc, 13 years ago

Milestone: R1R1/beta1

in reply to:  5 comment:9 by nielx, 12 years ago

Obsoleting patch because it needs more work: see comment:5

comment:10 by nielx, 12 years ago

patch: 10

comment:11 by scottmc, 12 years ago

Attached patches from GCI2012 student 'qxcv'. Can someone check these and see if they are acceptable.

comment:12 by axeld, 12 years ago

I'm not an expert, but I'd say the patches do look just fine.

comment:13 by korli, 12 years ago

Functions gamma_r and gammaf_r seem not part of the spec. IMO the patch 0005-Add-gamma-f-_r-declarations-and-aliases.patch isn't needed.

comment:14 by scottmc, 11 years ago

So then can someone apply patches 1-4 and then we can close this ticket out?

comment:15 by korli, 11 years ago

Resolution: fixed
Status: newclosed

Applied in hrev46161.

Note: See TracTickets for help on using tickets.