From 17b10f1bf34af6a740c3a999b740db9043154d55 Mon Sep 17 00:00:00 2001 From: Erik van der Kouwe Date: Fri, 8 Jan 2010 07:27:11 +0000 Subject: [PATCH] Add fabsf function --- include/math.h | 1 + lib/math/fabs.c | 7 +++++++ man/man3/fabs.3 | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 man/man3/fabs.3 diff --git a/include/math.h b/include/math.h index 8efaab15c..81778e429 100644 --- a/include/math.h +++ b/include/math.h @@ -24,6 +24,7 @@ _PROTOTYPE( double cos, (double _x) ); _PROTOTYPE( double cosh, (double _x) ); _PROTOTYPE( double exp, (double _x) ); _PROTOTYPE( double fabs, (double _x) ); +_PROTOTYPE( double fabsf, (float _x) ); _PROTOTYPE( double floor, (double _x) ); _PROTOTYPE( double fmod, (double _x, double _y) ); _PROTOTYPE( double frexp, (double _x, int *_exp) ); diff --git a/lib/math/fabs.c b/lib/math/fabs.c index 8c190c2c6..3cb12385f 100644 --- a/lib/math/fabs.c +++ b/lib/math/fabs.c @@ -6,8 +6,15 @@ */ /* $Header$ */ +float +fabsf(float x) +{ + return x < 0 ? -x : x; +} + double fabs(double x) { return x < 0 ? -x : x; } + diff --git a/man/man3/fabs.3 b/man/man3/fabs.3 new file mode 100644 index 000000000..bf90ea5ed --- /dev/null +++ b/man/man3/fabs.3 @@ -0,0 +1,18 @@ +.TH FABS 3 "January 7, 2009" +.UC 4 +.SH NAME +fabs, fabsf \- compute absolute value +.SH SYNOPSIS +.nf +.ft B +#include + +double fabs(double \fIx\fP); +float fabsf(float \fIx\fP); +.fi +.SH DESCRIPTION +\fBfabs\fP and \fBfabsf\fP return the absolute value of their argument. +.SH "RETURN VALUE +The return value is a number with the same magnitude as the argument and with +a positive sign. + -- 2.44.0