[FFmpeg-devel] [PATCHv2] configure+libm.h: add hypot emulation
Michael Niedermayer
michael at niedermayer.cc
Sun Nov 15 16:56:05 CET 2015
On Sun, Nov 15, 2015 at 10:03:37AM -0500, Ganesh Ajjanagadde wrote:
> It is known that the naive sqrt(x*x + y*y) approach for computing the
> hypotenuse suffers from overflow and accuracy issues, see e.g
> http://www.johndcook.com/blog/2010/06/02/whats-so-hard-about-finding-a-hypotenuse/.
> This adds hypot support to FFmpeg, a C99 function.
>
> On platforms without hypot, this patch does a reaonable workaround, that
> although not as accurate as GNU libm, is readable and does not suffer
> from the overflow issue. Improvements can be made separately.
>
> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
> ---
> configure | 2 ++
> libavutil/libm.h | 23 +++++++++++++++++++++++
> 2 files changed, 25 insertions(+)
>
> diff --git a/configure b/configure
> index d518b21..45df724 100755
> --- a/configure
> +++ b/configure
> @@ -1774,6 +1774,7 @@ MATH_FUNCS="
> exp2
> exp2f
> expf
> + hypot
> isinf
> isnan
> ldexpf
> @@ -5309,6 +5310,7 @@ disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h DtsCrystalHDVersi
>
> atan2f_args=2
> copysign_args=2
> +hypot_args=2
> ldexpf_args=2
> powf_args=2
>
> diff --git a/libavutil/libm.h b/libavutil/libm.h
> index 6c17b28..f7a2b41 100644
> --- a/libavutil/libm.h
> +++ b/libavutil/libm.h
> @@ -102,6 +102,29 @@ static av_always_inline av_const int isnan(float x)
> }
> #endif /* HAVE_ISNAN */
>
> +#if !HAVE_HYPOT
> +#undef hypot
> +static inline av_const double hypot(double x, double y)
> +{
> + double ret, temp;
> + x = fabs(x);
> + y = fabs(y);
> +
> + if (isinf(x) || isinf(y))
> + return av_int2double(0x7ff0000000000000);
if either is NaN the result should be NaN i think
return x+y
might achive this
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151115/5074e635/attachment.sig>
More information about the ffmpeg-devel
mailing list