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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:25:20+00:00 2026-05-12T06:25:20+00:00

The following command returns 1: ismember(-0.6, -1:.1:.9) but this next command returns 0: ismember(-0.1,

  • 0

The following command returns 1:

ismember(-0.6, -1:.1:.9)

but this next command returns 0:

ismember(-0.1, -1:.1:.9)

even though -0.1 clearly is in -1:.1:.9.

Does anybody know what’s going on?

  • 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-12T06:25:20+00:00Added an answer on May 12, 2026 at 6:25 am

    The problem is that when you start at -1.0 and add 0.1 repeatedly you get a slightly different number than if you specify -0.1 directly. This is because of floating-point error accumulation. Just like 1/3 cannot be represented exactly in decimal (it becomes 0.33333…), many decimal numbers cannot be represented exactly in binary. 0.1 when converted to binary is actually a very close approximation to 0.1. Because there is a slight error when you do arithmetic with this floating point number this small difference accumulates and becomes bigger and bigger.

    From http://www.mathworks.com/matlabcentral/newsreader/view_thread/246492:

    Ashwini Deshpande wrote:


    I have a matrix as follows,

    a = 0:0.1:1;
    

    when I tried to find whether 0.300 is present in the matrix a, using the following procedure,

    >> [tf, loc]=ismember(0.3,a)
    

    I got the following result:

    tf =
         0
    loc =
         0
    

    But it’s suppose to give me, tf = 1 and loc =4.


    You’re getting the correct result, actually. Look what happens:

         v=0:.1:1;
         n=0.3;
         sprintf('%30.20f\n',v(4),n)
    %{
         0.30000000000000004000 % <- result from vec
         0.29999999999999999000 % <- result from handwritten number
    %}
         format hex;
         [v(4),n,v(4)-n].'
    %{
         3fd3333333333334 % <- vec
         3fd3333333333333 % <- num
         3c90000000000000 % <- diff
    %}
         format;
    

    Also, peruse http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F

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

Sidebar

Related Questions

Following command will let me know the names of databases. $ mysqlshow But how
Odd one this... The following command returns what I would expect when I run
I currently use the following command, but it's a little unwieldy to type. What's
On a linux system, your standard uptime command returns the following: 6.46, 6.00, 4.51
I am using CoreData and executing the following command returns a number of objects:
I have the following command that returns a date from a file tail -1
In bourne shell I have the following: VALUES=`some command that returns multiple line values`
The following sed command from commandline returns what I expect. $ echo './Adobe ReaderScreenSnapz001.jpg'
How do you return 0 instead of null when running the following command: SELECT
The following command gives many manuals of Zsh man zsh<tab> alt text http://dl.getdropbox.com/u/175564/zsh.png I

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.