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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:44:47+00:00 2026-06-15T12:44:47+00:00

I figured out that double type on my machine corresponds to this Wikipedia article,

  • 0

I figured out that double type on my machine corresponds to this Wikipedia article, and long double corresponds to this text: x86 Extended Precision Format.

That’s why floor(52/log2(10)) or 15 digits of double should be correct and floor(63/log2(10)) or 19 digits of long double are trusted.

The code:

int main()
{
    double d=0.1;
    long double ld=0.1;

    std::cout.precision(19);
    std::cout.setf(std::ios_base::scientific);

    std::cout << d << std::endl;
    std::cout << ld << std::endl;

    return 0;
}

gives the output:

1.0000000000000000555e-01
1.0000000000000000555e-01

If we set cout.precision to 16, the output will be:

1.0000000000000001e-01
1.0000000000000001e-01

It’s allright, that 17th digit of double in 1st output and 16th digit of double in second output is incorrect. But why is it incorrect for long double? Is there a way to get all 19 correct digits of long double variables?

If I try printf("%.19Le\n",ld); for long double, I get exactly the same result.

I use OpenSUSE 12.1 and g++ 4.6.2.

  • 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-06-15T12:44:49+00:00Added an answer on June 15, 2026 at 12:44 pm

    The 0.1 literal constant is not a long double, it is probably a double .

    You may want to initialize ld with

     long double ld = (long double) 1.0 / (long double) 10.0;
    

    So that the division involves two long double operands, so hopefully is done in long double (I am not sure of that, you have to double check the appropriate C++ standards).

    And you probably want to compile with GCC supporting the latest standard. With a GCC 4.7 I would suggest to compile with g++ -Wall -std=c++11 but with your 4.6 you may need to say -std=c++0x

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

Sidebar

Related Questions

I figured out that a constant literal get's placed in the data segment of
I figured out that CUDA does not work in 64bit mode on my mac
I figured out that of course . and SPACE aren't allowed. Are there other
I've figured out that the problem is only with the Build Settings tab. So
I've figured out that default ReceiveBufferSize (8192) doesn't work for me - I lose
I created an UIViewController subclass, and figured out that the default implementation of -loadView
After some trial and error (ok, just error) I figured out that c089b69c3d contained
I'm writing HFT trading software. I'm trying to optimize it. I figured out that
I've figured out, that it's quite easy to purge a ressource out of Varnish
I've figured out a way to cache data (so that I won't have to

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.