2010-03-09 15:10:23 +00:00
|
|
|
/*
|
2011-03-18 17:35:10 +00:00
|
|
|
* This file is part of Libav.
|
2010-03-09 15:10:23 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2010-03-09 15:10:23 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2010-03-09 15:10:23 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 17:35:10 +00:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2010-03-09 15:10:23 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2010-03-09 15:10:23 +00:00
|
|
|
* Replacements for frequently missing libm functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVUTIL_LIBM_H
|
|
|
|
#define AVUTIL_LIBM_H
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include "config.h"
|
2010-03-09 16:17:59 +00:00
|
|
|
#include "attributes.h"
|
2012-06-26 16:22:12 +00:00
|
|
|
#include "intfloat.h"
|
2010-03-09 15:10:23 +00:00
|
|
|
|
2012-06-22 14:37:46 +00:00
|
|
|
#if !HAVE_CBRTF
|
|
|
|
static av_always_inline float cbrtf(float x)
|
|
|
|
{
|
|
|
|
return x < 0 ? -powf(-x, 1.0 / 3.0) : powf(x, 1.0 / 3.0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-09 15:10:23 +00:00
|
|
|
#if !HAVE_EXP2
|
|
|
|
#undef exp2
|
|
|
|
#define exp2(x) exp((x) * 0.693147180559945)
|
|
|
|
#endif /* HAVE_EXP2 */
|
|
|
|
|
|
|
|
#if !HAVE_EXP2F
|
|
|
|
#undef exp2f
|
|
|
|
#define exp2f(x) ((float)exp2(x))
|
|
|
|
#endif /* HAVE_EXP2F */
|
|
|
|
|
2012-06-26 16:22:12 +00:00
|
|
|
#if !HAVE_ISINF
|
|
|
|
static av_always_inline av_const int isinf(float x)
|
|
|
|
{
|
|
|
|
uint32_t v = av_float2int(x);
|
|
|
|
if ((v & 0x7f800000) != 0x7f800000)
|
|
|
|
return 0;
|
|
|
|
return !(v & 0x007fffff);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ISINF */
|
|
|
|
|
|
|
|
#if !HAVE_ISNAN
|
|
|
|
static av_always_inline av_const int isnan(float x)
|
|
|
|
{
|
|
|
|
uint32_t v = av_float2int(x);
|
|
|
|
if ((v & 0x7f800000) != 0x7f800000)
|
|
|
|
return 0;
|
|
|
|
return v & 0x007fffff;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ISNAN */
|
|
|
|
|
2010-03-09 15:10:23 +00:00
|
|
|
#if !HAVE_LLRINT
|
|
|
|
#undef llrint
|
|
|
|
#define llrint(x) ((long long)rint(x))
|
|
|
|
#endif /* HAVE_LLRINT */
|
|
|
|
|
2010-04-23 16:28:10 +00:00
|
|
|
#if !HAVE_LLRINTF
|
|
|
|
#undef llrintf
|
|
|
|
#define llrintf(x) ((long long)rint(x))
|
|
|
|
#endif /* HAVE_LLRINT */
|
|
|
|
|
2010-03-09 15:10:23 +00:00
|
|
|
#if !HAVE_LOG2
|
|
|
|
#undef log2
|
|
|
|
#define log2(x) (log(x) * 1.44269504088896340736)
|
|
|
|
#endif /* HAVE_LOG2 */
|
|
|
|
|
|
|
|
#if !HAVE_LOG2F
|
|
|
|
#undef log2f
|
|
|
|
#define log2f(x) ((float)log2(x))
|
|
|
|
#endif /* HAVE_LOG2F */
|
|
|
|
|
2012-06-26 12:05:28 +00:00
|
|
|
#if !HAVE_RINT
|
|
|
|
static inline double rint(double x)
|
|
|
|
{
|
|
|
|
return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_RINT */
|
|
|
|
|
2010-03-09 15:10:23 +00:00
|
|
|
#if !HAVE_LRINT
|
|
|
|
static av_always_inline av_const long int lrint(double x)
|
|
|
|
{
|
|
|
|
return rint(x);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LRINT */
|
|
|
|
|
|
|
|
#if !HAVE_LRINTF
|
|
|
|
static av_always_inline av_const long int lrintf(float x)
|
|
|
|
{
|
|
|
|
return (int)(rint(x));
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LRINTF */
|
|
|
|
|
|
|
|
#if !HAVE_ROUND
|
|
|
|
static av_always_inline av_const double round(double x)
|
|
|
|
{
|
|
|
|
return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ROUND */
|
|
|
|
|
|
|
|
#if !HAVE_ROUNDF
|
|
|
|
static av_always_inline av_const float roundf(float x)
|
|
|
|
{
|
|
|
|
return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ROUNDF */
|
|
|
|
|
2011-04-21 11:02:38 +00:00
|
|
|
#if !HAVE_TRUNC
|
|
|
|
static av_always_inline av_const double trunc(double x)
|
|
|
|
{
|
|
|
|
return (x > 0) ? floor(x) : ceil(x);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_TRUNC */
|
|
|
|
|
2010-03-09 15:10:23 +00:00
|
|
|
#if !HAVE_TRUNCF
|
|
|
|
static av_always_inline av_const float truncf(float x)
|
|
|
|
{
|
|
|
|
return (x > 0) ? floor(x) : ceil(x);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_TRUNCF */
|
|
|
|
|
|
|
|
#endif /* AVUTIL_LIBM_H */
|