[FFmpeg-devel] [PATCH 3/4] cos_tablegen: Don't use lrint

James Almer jamrial at gmail.com
Wed Jan 16 00:16:22 CET 2013


On 15/01/13 6:28 PM, Derek Buitenhuis wrote:
> You cannot count on it being present on all systems, and you
> cannot include libm.h in a host tool, so just hard code a baseline
> implementation.
> 
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
> ---
>  libavcodec/cos_tablegen.c |   13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/cos_tablegen.c b/libavcodec/cos_tablegen.c
> index 313a1d2..48b7b90 100644
> --- a/libavcodec/cos_tablegen.c
> +++ b/libavcodec/cos_tablegen.c
> @@ -37,11 +37,16 @@ static int clip_f15(int v)
>  
>  static void printval(double val, int fixed)
>  {
> -    if (fixed)
> -        printf(" "FIXEDFMT",", clip_f15(lrint(val * (double)(1<<15))));
> -    else
> -        printf(" "FLOATFMT",", val);
> +    if (fixed) {
> +        /* lrint() isn't always available, so round and cast manually. */
> +        double new_val = val * (double) (1 << 15);
> +
> +        new_val = new_val >= 0 ? floor(new_val + 0.5) : ceil(new_val - 0.5);
>  
> +        printf(" "FIXEDFMT",", clip_f15((long int) new_val));
> +    } else {
> +        printf(" "FLOATFMT",", val);
> +    }
>  }
>  
>  int main(int argc, char *argv[])

You could instead include libavutil/libm.h, which checks for HAVE_RINT, HAVE_LRINT
and HAVE_LLRINT, adding a replacement for them if they are not available that is
essentially the same code you're adding here and in the next patch.

Regards.


More information about the ffmpeg-devel mailing list