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 3635360
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:53:39+00:00 2026-05-19T00:53:39+00:00

I am calculating square root of 2147483647 by sqrt function.and the result must be

  • 0

I am calculating square root of 2147483647 by sqrt function.and the result must be a float value 46340.95 but my code returns the value 46341.
Can anyone tell me where is the problem?
i am using code :

double x=2147483647.0;
double y=sqrt(x);
cout<< y;
  • 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-19T00:53:39+00:00Added an answer on May 19, 2026 at 12:53 am

    I get that same result. But, if I inject a setprecision, I get the right value:

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    
    int main (void) {
        double x=2147483647.0;
        double y=sqrt(x);
        std::cout << std::setprecision(10) << y << std::endl;
        return 0;
    }
    

    gives me:

    46340.95
    

    In fact, if you use the folowing code:

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    
    int main (void) {
        double x=2147483647.0;
        double y=sqrt(x);
        std::cout << y << std::endl;
        std::cout << std::setprecision(0) << std::fixed << y << std::endl;
        std::cout << std::setprecision(1) << std::fixed << y << std::endl;
        std::cout << std::setprecision(2) << std::fixed << y << std::endl;
        std::cout << std::setprecision(3) << std::fixed << y << std::endl;
        return 0;
    }
    

    you get:

    46341
    46341
    46341.0
    46340.95
    46340.950
    

    So it appears that the default setting (at least for my environment) is a precision of zero.

    If you want a specific format, I suggest you explicitly request it.

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

Sidebar

Related Questions

I am calculating one parameter(X) this way: <?php $link=mysql_connect(localhost,root,); mysql_select_db(hand); $result = mysql_query(select *
I am calculating the Correct height of my Dynamic textView . But i am
I've got this script for calculating square area, which works perfect: <script language=javascript type=text/javascript>
So apparently calculating square roots is not very efficient, which leaves me wondering what
I am solving a numerical approximation (square root of two) up to a million
Does anyone know how the std::sqrt() function works? (or at least have an idea?)
I'm writing a function that exponentiates an object, i.e. given a and n, returns
I am calculating the inverse of a square matrix using different libraries via Cholesky
Calculating the area of a simple irregular polygon is trivial . However, consider the
Possible Duplicate: Calculating the Difference Between Two Java Date Instances How do I get

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.