Summary:ASTERISK-16854: [patch] roundf causing asterisk to fail to compile
Reporter:Ovidiu Sas (ovi)Labels:
Date Opened:2010-10-22 15:56:03Date Closed:2013-01-19 14:50:20.000-0600
Versions:Frequency of
Environment:Attachments:( 0) 20110107__issue18193__1.8.diff.txt
( 1) 20110107__issue18193.diff.txt
( 2) issueA16854_add_roundf_compat.patch
( 3) roundf.patch
Description:roundf is not available on some embedded systems and this is causing the compilation to fail.
By applying the following patch, the issue was circumvented:

<inline patch removed by lmadsen>

Can we add a detection for roundf during configure and ifdef the roundf call?
Comments:By: Leif Madsen (lmadsen) 2010-11-01 14:26:53

We cannot accept patches inline like you've provided, so I've deleted it.

Please follow the guidelines and sign the electronic license agreement (if not already done so) and attach the patch to the issue and mark it as code.


By: Leif Madsen (lmadsen) 2011-01-06 15:07:52.000-0600

Thanks for the patch! Sorry for the delay.

By: Tilghman Lesher (tilghman) 2011-01-07 12:30:30.000-0600

If your system does not have roundf(), does it have round()?  Both functions are required for C99 compliance, which is one of our requirements.  In any case, this patch is not correct, as it applies floor(), not round() functionality.

By: Walter Doekes (wdoekes) 2011-01-10 10:26:39.000-0600

I don't know if it would cause problems, but

#define roundf(a) ((float) (int) ((a) + 0.5))

is wrong.

The manual for round states that it should round halfway cases away from zero.

See this:

walter@walter-laptop:0:~$ cat 1.c
#include <stdio.h>
#include <math.h>
#define bad_roundf(a) ((float) (int) ((a) + 0.5))
float better_roundf(float a) { if (a < 0.0) return (float)(int)((a) - 0.5); return (float)(int)((a) + 0.5); }
int main() {
printf("%.1f %.1f\n", roundf(0.5), roundf(-0.5));
printf("%.1f %.1f\n", bad_roundf(0.5), bad_roundf(-0.5));
printf("%.1f %.1f\n", better_roundf(0.5), better_roundf(-0.5));
return 0;
walter@walter-laptop:0:~$ gcc 1.c
walter@walter-laptop:0:~$ ./a.out
1.0 -1.0
1.0 0.0
1.0 -1.0

By: Tilghman Lesher (tilghman) 2011-01-10 11:56:38.000-0600

wdoekes:  fair enough, but in all of Asterisk's cases, we are dealing with positive numbers only.  The real question is whether it resolves the problem with the embedded system not having roundf().

By: Ovidiu Sas (ovi) 2011-01-10 12:48:19.000-0600

The provided patch was first applied to asterisk 1.6 version (end of 2009) and then to 1.8.
The patch was used for all embedded builds (including the ones that provide roundf).  No complains so far.

By: Ovidiu Sas (ovi) 2013-01-03 17:29:22.791-0600

I see that roundf is used more and more in the code.
Can we have a workaround for this issue?

By: Rusty Newton (rnewton) 2013-01-07 16:29:53.340-0600

Ovidiu - you are welcome to ping community developers in #asterisk-dev and see if someone is willing to address Walter's concerns with your patch and push the patch through. This issue is in the Digium team's queue, but has many issues ahead of it.

By: Walter Doekes (wdoekes) 2013-01-18 05:31:31.830-0600

This should address my concerns.