round and M_PI

R

Rob Williscroft

JustSomeGuy wrote in @news3.calgary.shaw.ca:
In MS Visual C++ 6.0

Where is M_PI defined?
Where is round defined?

They are not defined in standard C++, If you need to know about
Visual C++ ask in one of the ms newsgroups, or do this:

#include <iostream>
#include <ostream>
#include <iomanip>
#include <cmath>
#include <limits>

double const m_pi = 2 * acos(0.0);

inline double round( double d )
{
return floor( d + 0.5 );
}

int main()
{
using namespace std;

cout << setprecision( numeric_limits< double >::digits10 );

cout << m_pi << endl;

cout << floor( m_pi ) << endl;
cout << floor( -m_pi ) << endl;

cout << ceil( m_pi ) << endl;
cout << ceil( -m_pi ) << endl;

cout << round( m_pi ) << endl;
cout << round( -m_pi ) << endl;
}

HTH


Rob.
 
P

PT

In MS Visual C++ 6.0
Where is M_PI defined?

Sorry, I use g++, not MS Visual C++, but maybe I can still be useful...

At my system, M_PI is not defined as such (it doesn't have any memory
associated with it), it's just a macro declared (#define'd) in math.h.
Where is round defined?

round is also declared in math.h (it has a prototype there), but it's
defined somewhere in the maths library (I don't know exactly, which one do
you have).
 
V

Victor Bazarov

PT said:
Sorry, I use g++, not MS Visual C++, but maybe I can still be useful...

At my system, M_PI is not defined as such (it doesn't have any memory
associated with it), it's just a macro declared (#define'd) in math.h.


round is also declared in math.h (it has a prototype there), but it's
defined somewhere in the maths library (I don't know exactly, which one do
you have).

Neither of the names in the subject line is standard. Not that
it can't be found on your system, just that it's not necessarily
there.

Victor
 
P

Pete Becker

Victor said:
Neither of the names in the subject line is standard.

To expand a bit: round is not standard C++, but it's standard C, having
been added in C99.
 
J

JustSomeGuy

Must be that Micro$oft decided that PI wasn't object oriented, and that no
one would need a rounding method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,814
Members
47,359
Latest member
Claim Bitcoin Earnings. $

Latest Threads

Top