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

  • Home
  • SEARCH
  • 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 7413839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:57:54+00:00 2026-05-29T06:57:54+00:00

I am trying to understand why using ‘/’ with long double in the following

  • 0

I am trying to understand why using ‘/’ with long double in the following way leads to a 0.000000 value while the same code with double does not

double d = (double)total_results / (double)total_points;

Gives the value 0.785403 but

long double d = (long double)total_results / (long double)total_points;

Gives the value 0.000000. I am trying to get the most accurate value for ‘total_results / total_points’

EDIT: In the end the error was simply that I was outputting it using ‘%f’ instead of ‘%Lf’

Before

printf("Running on %d thread(s), results is %f.\n", NUM_THREADS, d);    

After

printf("Running on %d thread(s), results is %Lf.\n", NUM_THREADS, d); 
  • 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-29T06:57:54+00:00Added an answer on May 29, 2026 at 6:57 am

    This is obviously just a guess, but how are you outputting the results? If you’re using printf with the wrong field specifier, printing an erroneous zero is definitely a possible result. Using g++, I tried “%lf” and got “-2.0000” when I should have gotten “0.75”. The right specifier is “%Lf”, with a capital L.

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

Sidebar

Related Questions

I was just trying to understand delegates using the following code. public class delegatesEx
I was trying to understand the floating point representation in C using this code
I am using code contracts and trying to understand which of the build options
I am trying to understand the proper way of using Grand Central Dispatch (GCD)
Trying to understand why you can't use sql_variant for the value type when using
I am trying to understand how the following scenario could be implemented using reactive
I'm trying to understand a method using the disassembly feature of Reflector. As anyone
Trying to understand an fft (Fast Fourier Transform) routine I'm using (stealing)(recycling) Input is
I'm trying to understand how parallelism might work using PLINQ, given delayed execution. Here
I am trying to understand if I really have any case for using git/mercurial.

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.