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

 
 

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

Submitter:  None
Submitted:  Thu 25 Aug 2016 10:26:34 AM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.0.3
Operating System:  * Mac OS Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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 Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-08-25 jwe StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code