NO

Author Topic: Where is round() function?  (Read 5495 times)

Zink

  • Guest
Where is round() function?
« on: December 07, 2009, 10:13:17 PM »
I tried to use round() function in my PPC application, but I'm getting "POLINK: error: Unresolved external symbol 'round'.". The same for roundf() and rintf(). Using PellesC 5.00.8.

I thought they were standard functions, so they shouldn't require any andditional libraries. I have listed all WinCE libraries anyway, and found no round() function, so I guess they aren't available on WinCE. But why would so basic function be not available? I guess I could write myself a round() equivalent, but I would rather like to use a standard one if it was available.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: Where is round() function?
« Reply #1 on: December 10, 2009, 06:00:25 AM »
In my Win32 setup, v 6.00.4 (32 bit), it is in various forms in math.h, where I would expect it...  :-\

Ralf

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Where is round() function?
« Reply #2 on: December 10, 2009, 10:39:49 AM »
In my Win32 setup, v 6.00.4 (32 bit), it is in various forms in math.h, where I would expect it...  :-\

Ralf
I made a text search in the WinCE libraries and I did not find any round-function. So I assume that Pelle has no round-function for WinCE.
EDIT: But if it helps you, you can use casting of a float variable to int:
Code: [Select]
float f = 5.5;
 int i = (int) f;
« Last Edit: December 10, 2009, 11:03:04 AM by AlexN »
best regards
 Alex ;)

JohnF

  • Guest
Re: Where is round() function?
« Reply #3 on: December 10, 2009, 11:26:52 AM »
A rough and ready round function can be implemented like so;

Code: [Select]
int myround(double number)
{
return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5);
}

John

« Last Edit: December 10, 2009, 11:28:27 AM by JohnF »

Zink

  • Guest
Re: Where is round() function?
« Reply #4 on: December 10, 2009, 05:16:08 PM »
I have found in PellesC help the page about intrinsic functions, and there is an information that rint() (which is just round() returning integer) is not available for ARM, so I guess it's the same for round() too.

I have written this function for rounding:
Code: [Select]
int froundi(float val)
{
  if (val - floor(val) < 0.5)
    return floor(val);
  else
    return ceil(val);
}


but JohnF's version seems better.

Thanks.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: Where is round() function?
« Reply #5 on: December 10, 2009, 05:55:44 PM »
In my Win32 setup, v 6.00.4 (32 bit), it is in various forms in math.h, where I would expect it...  :-\

Ralf
I made a text search in the WinCE libraries and I did not find any round-function. So I assume that Pelle has no round-function for WinCE.
:oops: Sorry, my bad, I missed that he was not using a Win(32) setup/target... :-(

Ralf

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Where is round() function?
« Reply #6 on: December 10, 2009, 09:01:26 PM »
A rough and ready round function can be implemented like so;

Code: [Select]
int myround(double number)
{
return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5);
}

John



Good but I would prefer this:
Code: [Select]
#define round(x) ((x >= 0) ? (int)(x + 0.5) : (int)(x - 0.5))

It works for float, double and long double and you don't have the framework of a function call.
best regards
 Alex ;)

JohnF

  • Guest
Re: Where is round() function?
« Reply #7 on: December 10, 2009, 09:22:59 PM »
Zink,

I think that because of memory constrains with the PPC various standard functions are missing that are normally included.

John