int a = round (2.6);
I have, of course, included <cmath> and i can go flooring and
ceiling with no problems. However, the rounding seems not to
be working at all. The compiler barks out that:
Error 3 error C3861: 'round': identifier not found
and that's the end of this story. I can (and most likely
will) simply add 0.5 and the floor-ify the result but
that's just wrong, so wrong...
What can be the reason? The remedy?
--
Vänligen Kerstin Viltersten
(The Cool Giraffe)
A quick look in the standard gives that answer that there is no round()
function. The remedy is to get a C99 compliant library and include
<math.h> (round() was included first in C99).
--
Erik Wikström
--
Ian Collins.
I find that astonishing... Well, i know how to work around
it so the question was purely academic. Thanks to all of
you. It's appreciated.
--
Ian Collins.
Astonishing, or at least surprising. Why? Well, intuitively speaking,
i'd expect a routine for _rounding_ to be there, if there's one for
_flooring_ and _ceiling_. I guess, in my view, they are the three
musketeers going together.
Of course it's not impossible but i'd be surprised too if a math
package would include sine but not cosine... I hope that answered
your question.
You could alternatively write:
int a = int(std::floor(var + 0.5));
round is required by TR1, and is included in our complete version
available at our web site. It has also been voted into C++0X, so in
a few years it'll be a required part of Standard C++.
And BTW, round isn't as easy to implement as you might think,
particularly if you want to honor the current floating-point rounding
mode.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
*when* will actually the new C++ standard come out ? I have heard a
lot of talk about it but haven't seen any concrete dates/years.
br/ajk
As I understand they (the committee) are aiming at 2009, which means
that they'll have to have a document ready to present to ISO at the end
of this year.
--
Erik Wikström
The value returned by round can be assigned to an int. What's your point?
--
-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)