Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 740045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:28:12+00:00 2026-05-14T08:28:12+00:00

In C++, const double Pi = 3.14159265; cout << sin(Pi); // displays: 3.58979e-009 it

  • 0

In C++,

const double Pi = 3.14159265;
cout << sin(Pi);                          // displays: 3.58979e-009

it SHOULD display the number zero

I understand this is because Pi is being approximated, but is there any way I can have a value of Pi hardcoded into my program that will return 0 for sin(Pi)? (a different constant maybe?)

In case you’re wondering what I’m trying to do: I’m converting polar to rectangular, and while there are some printf() tricks I can do to print it as “0.00”, it still doesn’t consistently return decent values (in some cases I get “-0.00”)

The lines that require sin and cosine are:

x = r*sin(theta);
y = r*cos(theta);

BTW: My Rectangular -> Polar is working fine… it’s just the Polar -> Rectangular

Thanks!

edit: I’m looking for a workaround so that I can print sin(some multiple of Pi) as a nice round number to the console (ideally without a thousand if-statements)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:28:13+00:00Added an answer on May 14, 2026 at 8:28 am

    What Every Computer Scientist Should Know About Floating-Point Arithmetic (edit: also got linked in a comment) is pretty hardcore reading (I can’t claim to have read all of it), but the crux of it is this: you’ll never get perfectly accurate floating point calculations. From the article:

    Squeezing infinitely many real numbers into a finite number of bits requires an approximate representation.

    Don’t let your program depend on exact results from floating point calculations – always allow a tolerance range. FYI 3.58979e-009 is about 0.0000000036. That’s well within any reasonable tolerance range you choose!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is this code: #include <iostream> template<const double& f> void fun5(){ std::cout << f
There is this code: #include <iostream> template<const double& f> void fun5(){ std::cout << f
I use operator() as a subscript operator this way: double CVector::operator() (int i) const
Consider a class like this one: class MyReferenceClass { public: MyReferenceClass(); const double ImportantConstant1;
Suppose i have: double f(const double *r) { return 0*(r[0]*r[1]); } should compiler be
Is this undefined behavior in c++? #include <iostream> const double& abs(const double& x){ return
if I define my constant varibles in my header like this... extern const double
With the code, const double rotationStep = 0.001; const int N = 2*int(M_PI/rotationStep) +
I'm writing code in C++ and have defined PI as: const double MathConstants::PI =
-(IBAction)EnterButtonPressed:(id)sender { const char *sql = SELECT AccessCode FROM UserAccess; double result = ([Password.text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.