bugGNU Octave - Bugs: bug #30742, Function rem returns incorrect...

 
 

bug #30742: Function rem returns incorrect result for certain inputs

Submitted by:  Ian Gralinski <iang>
Submitted on:  Wed 11 Aug 2010 06:01:15 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: InvalidAssigned to: None
Originator Name: Ian GOpen/Closed: Closed
Release: 3.2.3Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Wed 11 Aug 2010 06:26:41 AM UTC, comment #1:

No, this is a misunderstanding on your side. The default data type in Octave is a base-2 floating point number, which can't exactly represent most decimal numbers (the reason for base 2 is speed).
Hence, when you enter 2e-5, the closest approximation is used instead, and likewise for 0.1e-5. That's why you don't get exact zero. Try this:

octave:1> 2e-5 / 0.1e-5 - 20
ans = 3.5527e-15

See? You can also try, e.g., in Python to confirm that this is a general issue and nothing specific to Octave:

Python 2.6.2 (r262:71600, Jun 17 2010, 13:37:45)
[GCC 4.4.1 [gcc-4_4-branch revision 150839]] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> 2e-5 / 0.1e-5 - 20

3.5527136788005009e-15

Unless you can work this around yourself by eliminating the common negative power of 10, you need a decimal number package. There used to be one on OctaveForge, but currently it seems unmaintained.

Jaroslav Hajek <highegg>
Wed 11 Aug 2010 06:01:15 AM UTC, original submission:

Octave Version: 3.2.3
Configured for "x86_64-pc-linux-gnu"
Running Ubuntu 10.04 64-bit

The function rem seems to produce incorrect results for a few different input cases. The following all produce incorrect results:

octave:24> rem(2e-5,0.1e-5)
ans = 3.3881e-21
octave:25> rem(3e-5,0.1e-5)
ans = 3.3881e-21
octave:26> rem(5e-5,0.1e-5)
ans = 6.7763e-21
octave:27> rem(8e-5,0.1e-5)
ans = 1.3553e-20
octave:28> rem(9e-5,0.1e-5)
ans = 1.3553e-20
octave:29> rem(9e-5,0.1e-6)
ans = 1.3553e-20

(All these should give the answer 0)

It seems to be something specific to the size of the input arguments, because the following produce the correct result:

octave:32> rem(2e5,0.1e5)
ans = 0
octave:33> rem(2e15,0.1e15)
ans = 0
octave:34> rem(2e-15,0.1e-15)
ans = 0

Ian Gralinski <iang>

 

(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 highegg (Posted a comment)
  • -unavailable- added by iang (Submitted the item)
  • -unavailable- added by iang
  •  

    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 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 11 Aug 2010 06:26:41 AM UTChigheggStatusNone=>Invalid
      Open/ClosedOpen=>Closed
    Wed 11 Aug 2010 06:01:15 AM UTCiangCarbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1