bugGNU Octave - Bugs: bug #48897, Same value but not equal?...

 
 

bug #48897: Same value but not equal? (1.235*10^5 == 123500 -> ans = 0)

Submitted by:  None
Submitted on:  Thu 25 Aug 2016 10:26:34 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: InvalidAssigned to: None
Originator Name: Originator Email: -unavailable-
Open/Closed: ClosedRelease: 4.0.3
Operating System: Mac OS

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 26 Aug 2016 02:37:35 AM UTC, comment #2:

Thank you for your quick response.
I took it this is inevitable affair when approximating decimal numbers from binary numbers.

Anonymous
Thu 25 Aug 2016 11:18:48 AM UTC, comment #1:

This is not a bug, this is just the way that floating point numerical operations work. Please read the FAQ about this:

http://wiki.octave.org/FAQ#Why_is_this_floating_point_computation_wrong.3F

John W. Eaton <jwe>
Project Administrator
Thu 25 Aug 2016 10:26:34 AM UTC, original submission:

Same value but not equal?

I found that octave works wrong with following specific value as follows:

>> x = 1.235*10^5

x = 1.2350e+05

>> y = 123500

y = 123500

>> x == y

ans = 0

Both x and y are double.
I found the difference between x and y after several trials:

>> typecast(x,"int8")

ans =

1 0 0 0 -64 38 -2 64

>> typecast(y, "int8")

ans =

0 0 0 0 -64 38 -2 64

The most significant bit of x is wrong here.
When I converted x to string and then reconverted to number, it turns OK.

>> str2num( num2str( x) ) == y

ans = 1

This is very weird. I hope this problem will be solved.
Thank you.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 25 Aug 2016 11:18:48 AM UTCjweStatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1