avr-libc: Built-in rounding function and documentation?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was just coding a small rounding function which, of course, is called 'round':

int16_t round(float f)
{
	uint16_t r;

	r=f+(f<0?-0.5:0.5);
	return r;
}

When compiling, I get the error:

Quote:
../main.c:935: warning: conflicting types for built-in function 'round'

I´ve included math.h from avr-libc and linked against libm.a. So my guess is that there already is a function called 'round'. Searching the avr-libc docs and the files in the avr-libc directory tree for 'round' turned up nothing related to a rounding function. If there´s documentation available on the function, where can I find it?

Thanks,

Ingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

round() is defined by the C standard. Albeit there's no
actual implementation for it in avr-libc, as you see, the
compiler supplies its own implementation. Per the C standard,
you are not allowed to redefine standard library functions
(at least not in hosted mode).

Here's what my FreeBSD manual says:

ROUND(3)               FreeBSD Library Functions Manual               ROUND(3)

NAME
     round, roundf, roundl -- round to nearest integral value

LIBRARY
     Math Library (libm, -lm)

SYNOPSIS
     #include 

     double
     round(double x);

     float
     roundf(float x);

     long double
     roundl(long double x);
...

You might try declaring it that way, and see whether it will work (as
implemented implicitly by GCC). If not, just use a different name for
your own function, or disable any and all library-based assumptions by
using -ffreestanding (but that might prevent the compiler from using
some clever optimizations based on its internal knowledge about how the
standard library is supposed to work).

You might file a bug report (as enhancement request) for the libm
library in avr-libc to eventually implement, but I currently don't see
a volunteer to handle that.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dl8dtl wrote:
round() is defined by the C standard. Albeit there's no
actual implementation for it in avr-libc, as you see, the
compiler supplies its own implementation. Per the C standard,
you are not allowed to redefine standard library functions
(at least not in hosted mode).

Here's what my FreeBSD manual says:

[...]

You might try declaring it that way, and see whether it will work (as
implemented implicitly by GCC). If not, just use a different name for
your own function [...]


OK, I´ll try if it works ok or otherwise rename my own function.

Thanks,

Ingo