diff --git a/library/changes b/library/changes index 57d9620..53a5c81 100644 --- a/library/changes +++ b/library/changes @@ -61,6 +61,8 @@ tanhf(), tgamma(), tgammaf(), trunc() and truncf(), to be filled in later... +- Implemented fmin()/fminf(), fmax()/fmaxf(), fdim()/fdimf() (C99). + c.lib 1.192 (12.5.2005) diff --git a/library/include/math.h b/library/include/math.h index b97f0bf..a308e8f 100644 --- a/library/include/math.h +++ b/library/include/math.h @@ -1,5 +1,5 @@ /* - * $Id: math.h,v 1.11 2005-05-29 10:09:55 obarthel Exp $ + * $Id: math.h,v 1.12 2005-05-29 12:41:04 obarthel Exp $ * * :ts=4 * @@ -116,8 +116,8 @@ extern double hypot(double x,double y); /* Note that the comparison operations performed on the floating point data types ought to include float, double and long double. However, because the current (2005-06-12) compiler technology available on the - Amiga does not support the long double type yet, this library is restricted - to operations on float and double. */ + Amiga does not support the long double type yet, this library is + restricted to operations on float and double. */ /****************************************************************************/ @@ -134,8 +134,8 @@ extern float __nan; /****************************************************************************/ -#define INFINITY ((const float)__infinity) -#define NAN ((const float)__nan) +#define INFINITY ((const float)__infinity) +#define NAN ((const float)__nan) /****************************************************************************/ @@ -238,8 +238,23 @@ extern double nextafter(double x,double y); /****************************************************************************/ -extern double copysign(double x, double y); extern float copysignf(float x, float y); +extern double copysign(double x, double y); + +/****************************************************************************/ + +extern float fdimf(float x,float y); +extern double fdim(double x,double y); + +/****************************************************************************/ + +extern float fminf(float x,float y); +extern double fmin(double x,double y); + +/****************************************************************************/ + +extern float fmaxf(float x,float y); +extern double fmax(double x,double y); /****************************************************************************/ diff --git a/library/math_fdim.c b/library/math_fdim.c index 3d9c8f2..9c76d5d 100644 --- a/library/math_fdim.c +++ b/library/math_fdim.c @@ -1,5 +1,5 @@ /* - * $Id: math_fdim.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $ + * $Id: math_fdim.c,v 1.2 2005-05-29 12:41:03 obarthel Exp $ * * :ts=4 * @@ -44,8 +44,14 @@ double fdim(double x,double y) { - /* ZZZ unimplemented */ - return(0); + double result; + + if(x > y) + result = x - y; + else + result = 0; + + return(result); } /****************************************************************************/ diff --git a/library/math_fdimf.c b/library/math_fdimf.c index a15668a..89591d2 100644 --- a/library/math_fdimf.c +++ b/library/math_fdimf.c @@ -1,5 +1,5 @@ /* - * $Id: math_fdimf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $ + * $Id: math_fdimf.c,v 1.2 2005-05-29 12:41:03 obarthel Exp $ * * :ts=4 * @@ -44,8 +44,14 @@ float fdimf(float x,float y) { - /* ZZZ unimplemented */ - return(0); + float result; + + if(x > y) + result = x - y; + else + result = 0; + + return(result); } /****************************************************************************/ diff --git a/library/math_fmax.c b/library/math_fmax.c index b5458c6..3f15a48 100644 --- a/library/math_fmax.c +++ b/library/math_fmax.c @@ -1,5 +1,5 @@ /* - * $Id: math_fmax.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $ + * $Id: math_fmax.c,v 1.2 2005-05-29 12:41:03 obarthel Exp $ * * :ts=4 * @@ -44,8 +44,28 @@ double fmax(double x,double y) { - /* ZZZ unimplemented */ - return(0); + double result; + + if(isnan(x)) + { + if(isnan(y)) + result = nan(NULL); + else + result = y; + } + else if (isnan(y)) + { + result = x; + } + else + { + if(x > y) + result = x; + else + result = y; + } + + return(result); } /****************************************************************************/ diff --git a/library/math_fmaxf.c b/library/math_fmaxf.c index af68156..6a3053b 100644 --- a/library/math_fmaxf.c +++ b/library/math_fmaxf.c @@ -1,5 +1,5 @@ /* - * $Id: math_fmaxf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $ + * $Id: math_fmaxf.c,v 1.2 2005-05-29 12:41:03 obarthel Exp $ * * :ts=4 * @@ -44,8 +44,28 @@ float fmaxf(float x,float y) { - /* ZZZ unimplemented */ - return(0); + float result; + + if(isnan(x)) + { + if(isnan(y)) + result = nanf(NULL); + else + result = y; + } + else if (isnan(y)) + { + result = x; + } + else + { + if(x > y) + result = x; + else + result = y; + } + + return(result); } /****************************************************************************/ diff --git a/library/math_fmin.c b/library/math_fmin.c index 3b4de45..76a4118 100644 --- a/library/math_fmin.c +++ b/library/math_fmin.c @@ -1,5 +1,5 @@ /* - * $Id: math_fmin.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $ + * $Id: math_fmin.c,v 1.2 2005-05-29 12:41:03 obarthel Exp $ * * :ts=4 * @@ -44,8 +44,28 @@ double fmin(double x,double y) { - /* ZZZ unimplemented */ - return(0); + double result; + + if(isnan(x)) + { + if(isnan(y)) + result = nan(NULL); + else + result = y; + } + else if (isnan(y)) + { + result = x; + } + else + { + if(x < y) + result = x; + else + result = y; + } + + return(result); } /****************************************************************************/ diff --git a/library/math_fminf.c b/library/math_fminf.c index 168dab6..6010f69 100644 --- a/library/math_fminf.c +++ b/library/math_fminf.c @@ -1,5 +1,5 @@ /* - * $Id: math_fminf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $ + * $Id: math_fminf.c,v 1.2 2005-05-29 12:41:03 obarthel Exp $ * * :ts=4 * @@ -44,8 +44,28 @@ float fminf(float x,float y) { - /* ZZZ unimplemented */ - return(0); + float result; + + if(isnan(x)) + { + if(isnan(y)) + result = nanf(NULL); + else + result = y; + } + else if (isnan(y)) + { + result = x; + } + else + { + if(x < y) + result = x; + else + result = y; + } + + return(result); } /****************************************************************************/