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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:22:24+00:00 2026-06-06T23:22:24+00:00

From what I understand, the famous (0.1 + 0.2) !== 0.3 gotcha is not

  • 0

From what I understand, the famous

 (0.1 + 0.2) !== 0.3

gotcha is not actually Javascript’s fault. Thats just the way the IEEE 754 works. A similar output happens in Python, which also follows the IEEE 754 rules.

Then how come this particular example works as expected in C, sometimes. If I do a direct comparison

printf("%d\n", (0.1+0.2) == 0.3);

I get the (un?)expected output 0, but if I put the values into variables or print them out, I get properly rounded answers.

C Runnable Example

Is the C implementation of IEEE 754 doing something extra? Or is it something completely else that I am missing.

Update

The code sample I posted was broken due to a typo. Try this one
Fixed C Runnable Example

But the original Question still remains.

double d1, d2, d3;
d1 = 0.1;    d2 = 0.2;    d3 = d1 + d2;
printf ("%d\n", ((((double)0.1)+((double)0.2)) == ((double)d3)));
printf ("%.17f\n", d1+d2);
printf ("%d\n", ((d1+d2) == d3));

The output is

1
0.30000000000000004
1

The rephrased question now is:

  1. Why (and when, and how) is the C compiler taking the liberty to say that

    0.3 == 0.30000000000000004

  2. Given all facts, isn’t it true that the C implementation is broken, rather than Javascripts’?

  • 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-06T23:22:26+00:00Added an answer on June 6, 2026 at 11:22 pm

    Why (and when, and how) is the C compiler taking the liberty to say that

        0.3 == 0.30000000000000004
    

    Given all facts, isn’t it true that the C implementation is broken, rather than Javascripts’?

    It isn’t.

    The output given is from this code:

    printf ("%d\n", ((((double)0.1)+((double)0.2)) == ((double)d3)));
    

    but you wrote:

    d1 = 0.1;    d2 = 0.2;    d3 = d1 + d2;
    

    so d3 is not 0.3, it’s 0.30000000000000004

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

Sidebar

Related Questions

From what I understand there is no way of type-checking the messages send in
From what I understand, the best way to deal with dates in the Zend
I understand from this post that value types in C# are not objects. That
I am trying to understand the algorithm from the famous 'diff' paper here ,
I understand from the MSDN docs that the event DataReceived will not necessarily fire
I'd like to know if there is a way to understand from outside a
I understand from other posts that the only way to handle this is through
As you can understand from title, i modified Settings.cs file.Added some properties, some code
As far as I understand from the documentation the QUdpSocket are async but, still,
I found that Maven implies specific directory layout. But I don't understand from here:

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.