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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:03:41+00:00 2026-06-04T18:03:41+00:00

I was struck by this strange behavior: float pi = 3.14; if(pi == 3.14)

  • 0

I was struck by this strange behavior:

float pi = 3.14;

if(pi == 3.14)
    cout << "OK";
else
    cout << "How is it possible?";

Could anyone explain this?

  • 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-04T18:03:42+00:00Added an answer on June 4, 2026 at 6:03 pm

    The constant in the if statement is (double)3.14. It is very close to its float version, but not exactly equals it, because 3.14 is not represented exactly.

    Try the same trick with 1.25 or any other number that can be represented exactly, and you will get an OK.

    float num = 1.25;
    if(num == 1.25)
        cout << "OK";
    else
        cout << "How is it possible?";
    

    You could also cast 3.14 to float to get an OK:

    float pi = 3.14;
    
    if(pi == (float)3.14)
        cout << "OK";
    else
        cout << "How is it possible?";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This behavior is strange because I could not get the segfault if the shared
This may sound simple but i am stuck up at a very strange problem.
This struck me as really weird behaviour and I spent a while checking for
Temporary ASP.NET Files Missing I struck with this error at yesterday itself. I googled
I've encountered a strange behavior in __declspec(dllexport) in my project. I have a C++
I would appreciate help debugging some strange behavior by a multiset container. Occasionally, the
I am experiencing some very strange behavior with Blend: Since weeks i am working
This one is a little strange to me. I have a pointer to a
While creating the sample, I noticed very strange behavior and due to which I
I bumped into this strange macro code in /usr/include/linux/kernel.h : /* Force a compilation

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.