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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:15:28+00:00 2026-05-18T03:15:28+00:00

Possible Duplicate: How do I fix this Perl code so that 1.1 + 2.2

  • 0

Possible Duplicate:
How do I fix this Perl code so that 1.1 + 2.2 == 3.3?

I’m working on a Perl script that compares strings representing gene models and prints out a summary of the comparison. If the gene models match perfectly, I print out a very terse summary, but if they are different, the summary is quite verbose.

The script looks at the value of a variable to determine whether it should do the terse or verbose summary–if the variable is equal to 1, it should print the terse summary; otherwise, it should print the verbose summary.

Since the value is numeric (a float), I’ve been using the == operator to do the comparison.

if($stats->{overall_simple_matching_coefficient} == 1)
{
  print "Gene structures match perfectly!\n";
}

This worked correctly for all of my tests and even for most of the new cases I am running now, but I found a weird case where the value was equal to 1 but the above comparison failed. I have not been able to figure out why the comparison failed, and stranger yet, when I changed the == operator to the eq operator, it seemed to work fine.

I thought the == was for numerical comparison and eq was for string comparison. Am I missing something here?

Update: If I print out the value right before the comparison…

printf("Test: '%f', '%d', '%s'\n", $stats->{overall_simple_matching_coefficient}, $stats->{overall_simple_matching_coefficient}, $stats->{overall_simple_matching_coefficient});

…I get this.

Test: '1.000000', '0', '1'
  • 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-18T03:15:28+00:00Added an answer on May 18, 2026 at 3:15 am

    The first thing any computer language teacher should teach you about any computer language is that YOU CANNOT COMPARE FLOATS FOR EQUALITY. This is true of any language. Floating point arithmetic is not exact, and two floats that look like they’re the same will be different in the insignificant digits somewhere where you can’t see it. Instead, you can only compare that they are close to each other – like

    if (abs(stats->{overall_simple_matching_coefficient)-1) < 0.0001)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C# okay with comparing value types to null I was working on
Possible Duplicate: Not possible to launch a file on a network using Java Desktop?
Possible Duplicate: Cross-thread operation not valid: Control accessed from a thread other than the
Possible Duplicate: Why does BinaryWriter prepend gibberish to the start of a stream? How
Possible Duplicate: VS2005 Winforms Designer Exception Screen and IE8 All of the sudden, visual
Possible Duplicate: What is an undefined reference/unresolved external symbol error and how do I
Possible Duplicate: mysql_fetch_array() expects parameter 1 to be resource, boolean given in select When
Possible Duplicate: What is the best way to compare two entity framework entities? I
Possible Duplicate: How to properly clean up Excel interop objects in C# I've read
Possible Duplicate: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result $err =

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.