3

a few days ago, I worked on project in VC++. I found out, that math.h in VC++ differs much from dev-cpp math.h. Particulary its round function, that is not present in Visual C++ math.h, but is contained in dev-cpp math.h.

Now I would like to ask, whether it this caused by dev-cpp roots in myngw? Or whether its a different standard (ISO)

Thank everyone for response.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740

1 Answers1

4

round() is part of the C99 standard, which Visual Studio doesn't fully support. But you could easily write your own implementation:

double round(double r) {
    return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}
fschoenm
  • 1,391
  • 13
  • 32
  • Writing your own round function is [a hard problem](http://stackoverflow.com/a/24348037/1708801) your solution will not work for certain value as the linked answer explains. One example would be `0.49999999999999994`. Better advice would be to use boost. – Shafik Yaghmour Jul 21 '14 at 19:18
  • Or use Visual Studio 2013. Microsoft has added many C99 functions to that release, including (finally) ``round()``. – fschoenm Jul 22 '14 at 07:28