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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:34:27+00:00 2026-06-09T05:34:27+00:00

Possible Duplicate: In R, what is the difference between these two? floating point issue

  • 0

Possible Duplicate:
In R, what is the difference between these two?
floating point issue in R?

This is part of a code I created. I spend days looking for the problem when finally realized that a comparison that should be TRUE was being calculated by R as FALSE. I’m using R 2.14.2 64 bits on windows. This is the code to reproduce the problem.

concList= c(1.15, 1.15, 1.15 ,1.15 ,1.15 ,1.15 )
concList=concList-0.4
a=sum(concList)
b=length(concList)*0.75
str(a)
str(b)
print(a==b)

The last print will result in FALSE even thou they are shown as exactly the same number. I tough this could be some problem on the floating point numerical representation of R, so I added the code below which solves the problem.

a=round(a,1)
b=round(b,1)
print(a==b)

My question is, is there any more elegant solution? Is this a bug that should be reported?

Thanks for your time.

  • 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-09T05:34:29+00:00Added an answer on June 9, 2026 at 5:34 am

    Because they aren’t exactly the same number. They differ by a very small amount due to the computer’s representation of numbers, also known as floating point errors:

    > a - b
    [1] -8.881784e-16
    

    Jon Skeet has an excellent blog post on this issue, which pops up on Stack Overflow with some regularity.

    As @mrdwab suggests in the comments, you should use all.equal(a, b) to test for near equality.

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

Sidebar

Related Questions

Possible Duplicate: Is there any particular difference between intval and (int)? These two statements
Possible Duplicate: What is the difference between these two ways of allocating memory in
Possible Duplicate: C++ Why put void in params? What's the difference between these two
Possible Duplicate: difference between string object and string literal Let's say I have two
Possible Duplicate: Difference between int[] array and int array[] I was sure that this
Possible Duplicate: What is the difference between const and readonly? are these interchangeable? can
Possible Duplicate: C# “as” cast vs classic cast What is the difference between these
Possible Duplicate: How to calculate the difference between two dates using PHP? How to
Possible Duplicate: Debug/Release difference I want to know what do these two mean: Debug
Possible Duplicate: What is the difference between these jQuery ready functions? $(function(){ // ...

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.