Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What's up with rounding in cmath?!

0 views
Skip to first unread message

The Cool Giraffe

unread,
May 11, 2007, 5:01:14 PM5/11/07
to
I have trouble making the following line compile.

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)


Erik Wikström

unread,
May 11, 2007, 5:20:11 PM5/11/07
to

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

Message has been deleted

Ian Collins

unread,
May 11, 2007, 5:25:13 PM5/11/07
to
You might be able to get away with just changing the header to <math.h>
if your compiler's C mode uses the C99 library.

--
Ian Collins.

The Cool Giraffe

unread,
May 11, 2007, 6:09:42 PM5/11/07
to
Erik Wikström wrote/skrev/kaita/popisal/schreibt :


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

unread,
May 11, 2007, 6:43:26 PM5/11/07
to
Why is it astonishing? The round family of functions are new in C99, so
not part of the standard C++ library.

--
Ian Collins.

The Cool Giraffe

unread,
May 12, 2007, 3:37:33 AM5/12/07
to
Ian Collins wrote/skrev/kaita/popisal/schreibt :


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.

Juha Nieminen

unread,
May 12, 2007, 8:50:23 AM5/12/07
to
The Cool Giraffe wrote:
> int a = round (2.6);

You could alternatively write:

int a = int(std::floor(var + 0.5));

P.J. Plauger

unread,
May 12, 2007, 9:43:20 AM5/12/07
to
"The Cool Giraffe" <gira...@viltersten.com> wrote in message
news:5al8alF...@mid.individual.net...

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


ajk

unread,
May 12, 2007, 10:15:41 AM5/12/07
to

*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

Erik Wikström

unread,
May 12, 2007, 10:48:38 AM5/12/07
to

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

Pete Becker

unread,
May 12, 2007, 11:36:26 AM5/12/07
to
Salt_Peter wrote:
> On May 11, 5:01 pm, "The Cool Giraffe" <giraf...@viltersten.com>

>>
>> int a = round (2.6);
>>
>
> round() doesn't return an int, although thats not your problem.
>

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)

0 new messages