473,490 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What's up with rounding in cmath?!

I have trouble making the following line compile.

int a = round (2.6);

I have, of course, included <cmathand 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)
May 11 '07 #1
11 14976
On 2007-05-11 23:01, The Cool Giraffe wrote:
I have trouble making the following line compile.

int a = round (2.6);

I have, of course, included <cmathand 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?
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
May 11 '07 #2
On May 11, 5:01 pm, "The Cool Giraffe" <giraf...@viltersten.com>
wrote:
I have trouble making the following line compile.

int a = round (2.6);

I have, of course, included <cmathand 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)
round() doesn't return an int, although thats not your problem.

#include <iostream>
#include <cmath>

int main()
{
double result = round( 2.6 );
std::cout << "result = " << result << std::endl;
}

if you really need an int, use a static_cast< int >( )

May 11 '07 #3
Erik Wikström wrote:
On 2007-05-11 23:01, The Cool Giraffe wrote:
>I have trouble making the following line compile.

int a = round (2.6);

I have, of course, included <cmathand 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?

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).
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.
May 11 '07 #4
Erik Wikström wrote/skrev/kaita/popisal/schreibt :
On 2007-05-11 23:01, The Cool Giraffe wrote:
>I have trouble making the following line compile.

int a = round (2.6);

I have, of course, included <cmathand 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?

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).

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.

--
Vänligen Kerstin Viltersten
(The Cool Giraffe)
May 11 '07 #5
The Cool Giraffe wrote:
Erik Wikström wrote/skrev/kaita/popisal/schreibt :
>On 2007-05-11 23:01, The Cool Giraffe wrote:
>>I have trouble making the following line compile.

int a = round (2.6);

I have, of course, included <cmathand 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?
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).


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.
Why is it astonishing? The round family of functions are new in C99, so
not part of the standard C++ library.

--
Ian Collins.
May 11 '07 #6
Ian Collins wrote/skrev/kaita/popisal/schreibt :
The Cool Giraffe wrote:
>Erik Wikström wrote/skrev/kaita/popisal/schreibt :
>>On 2007-05-11 23:01, The Cool Giraffe wrote:
>>>I have trouble making the following line compile.

int a = round (2.6);

I have, of course, included <cmathand 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?
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).


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.
Why is it astonishing? The round family of functions are new in C99,
so not part of the standard C++ library.

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.

--
Vänligen Kerstin Viltersten
(The Cool Giraffe)
May 12 '07 #7
The Cool Giraffe wrote:
int a = round (2.6);
You could alternatively write:

int a = int(std::floor(var + 0.5));
May 12 '07 #8
"The Cool Giraffe" <gi******@viltersten.comwrote in message
news:5a*************@mid.individual.net...
Ian Collins wrote/skrev/kaita/popisal/schreibt :
>The Cool Giraffe wrote:
>>Erik Wikström wrote/skrev/kaita/popisal/schreibt :
On 2007-05-11 23:01, The Cool Giraffe wrote:
>>>>I have trouble making the following line compile.
>
int a = round (2.6);
>
I have, of course, included <cmathand 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?
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).
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.
Why is it astonishing? The round family of functions are new in C99,
so not part of the standard C++ library.


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.
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
May 12 '07 #9
ajk
On Sat, 12 May 2007 09:43:20 -0400, "P.J. Plauger"
<pj*@dinkumware.comwrote:
>"The Cool Giraffe" <gi******@viltersten.comwrote in message
news:5a*************@mid.individual.net...
>Ian Collins wrote/skrev/kaita/popisal/schreibt :
>>The Cool Giraffe wrote:
Erik Wikström wrote/skrev/kaita/popisal/schreibt :
On 2007-05-11 23:01, The Cool Giraffe wrote:
>>>>>I have trouble making the following line compile.
>>
>int a = round (2.6);
>>
>I have, of course, included <cmathand 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?
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).
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.

Why is it astonishing? The round family of functions are new in C99,
so not part of the standard C++ library.


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.

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
May 12 '07 #10
On 2007-05-12 16:15, ajk wrote:
On Sat, 12 May 2007 09:43:20 -0400, "P.J. Plauger"
<pj*@dinkumware.comwrote:
>>"The Cool Giraffe" <gi******@viltersten.comwrote in message
news:5a*************@mid.individual.net...
>>Ian Collins wrote/skrev/kaita/popisal/schreibt :
The Cool Giraffe wrote:
Erik Wikström wrote/skrev/kaita/popisal/schreibt :
>On 2007-05-11 23:01, The Cool Giraffe wrote:

>>I have trouble making the following line compile.
>>>
>>int a = round (2.6);
>>>
>>I have, of course, included <cmathand 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?
>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).
>
>
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.
>
Why is it astonishing? The round family of functions are new in C99,
so not part of the standard C++ library.
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.

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.
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
May 12 '07 #11
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)
May 12 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2109
by: Edwin Young | last post by:
Hi, I think there might (emphasize might) be a minor bug in Python's cmath library. Basically, Python says cmath.asin(0) = 0-0j (+0 real part, -0 imaginary part). I think it should be 0+0j...
3
1681
by: Peter Olsen | last post by:
I want to define a class "point" as a subclass of complex. When I create an instance sample = point(<arglist>) I want "sample" to "be" a complex number, but with its real and imaginary...
1
1515
by: Dr John Stockton | last post by:
When rounding (or truncating) a number which may be either positive or negative, it is sometimes necessary to round either towards plus infinity or towards minus infinity. But those are special...
4
2480
by: Daniel Billingsley | last post by:
I'm trying to figure out what happens when I cast a double with (int)... does it round or drop the decimal part? MS says: "When you convert from a double or float value to an integral type,...
3
6713
by: Norvin Laudon | last post by:
Hi, Can somebody explain the following, from the MSDN documentation for the "System.Convert.ToInt32(double)" function <quote> Return Value value rounded to the nearest 32-bit signed...
5
2242
by: Jason | last post by:
I am having a rounding problem in a value i am trying to display in VB.NET. If I have the following code: Dim x As Single = 2726.795 Dim y As Single = Math.Round(2726.795, 2) Dim s as String =...
52
1565
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
20
4955
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
30
29429
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.