rtt-f030/components/external/espruino/libs/math/fabs.c

57 lines
591 B
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* fabs.c
*
* Absolute value
*
*
*
* SYNOPSIS:
*
* double x, y;
*
* y = fabs( x );
*
*
*
* DESCRIPTION:
*
* Returns the absolute value of the argument.
*
*/
#include "mconf.h"
/* Avoid using UNK if possible. */
#ifdef UNK
#if BIGENDIAN
#define MIEEE 1
#else
#define IBMPC 1
#endif
#endif
double fabs(x)
double x;
{
union
{
double d;
short i[4];
} u;
u.d = x;
#ifdef IBMPC
u.i[3] &= 0x7fff;
#endif
#ifdef MIEEE
u.i[0] &= 0x7fff;
#endif
#ifdef DEC
u.i[3] &= 0x7fff;
#endif
#ifdef UNK
if( u.d < 0 )
u.d = -u.d;
#endif
return( u.d );
}