bugGNU Octave - Bugs: bug #26190, dec2base test fails due to...

 
 

bug #26190: dec2base test fails due to floating point error

Submitted by:  Thorsten Meyer <tmeyier>
Submitted on:  Wed 15 Apr 2009 05:16:36 PM UTC  
 
Category: LibrariesSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: Thorsten Meyer <tmeyier>
Originator Name: Open/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Fri 17 Apr 2009 08:07:56 PM UTC, comment #2:

dec2base tests pass with the fix.

Thanks

Thorsten

Thorsten Meyer <tmeyier>In charge of this item.
Thu 16 Apr 2009 06:27:29 AM UTC, comment #1:

A fix is online that should bring back the robustness w.r.t. integers. Please verify.

Jaroslav Hajek <highegg>
Wed 15 Apr 2009 05:16:36 PM UTC, original submission:

with the present tip (bb62bc406ea7) (and also with some other recent build, if I remember correctly) I get two fails for the tests in dec2base.
This simple example demonstrates the problem:
octave:160> dec2base(999, 10)
ans = 998

Looking into the code, the following lines seem to be responsible for the bug:
power = ones (length (n), 1) * (base .^ (max_len-1 : -1 : 0));
n = n(:) * ones (1, max_len);
digits = floor (rem (n, base*power) ./ power);

power is assigned a vector of powers of the base. However, due to floating point round off error, the numbers in power are not all integers. For the above example:
octave:161> max_len=3;
octave:162> base=10;
octave:163> n=999;
octave:167> max_len = round (log (max (max (n), 1)) ./ log (base)) + 1
octave:168> power = ones (length (n), 1) * (base .^ (max_len-1 : -1 : 0))
power =

1000.0000 100.0000 10.0000 1.0000

octave:170> power-1
ans =

9.9900e+02 9.9000e+01 9.0000e+00 2.2204e-16

octave:171> n = n(:) * ones (1, max_len);
octave:172> digits = floor (rem (n, base*power) ./ power)
digits =

0 9 9 8

power(4) is a bit larger than 1, hence the remainder is a bit too small leading to the result being rounded down to 8.

Changing the definition of power to
power = ones (length (n), 1) * round (base .^ (max_len-1 : -1 : 0));

seems to fix the problem.

Still, before making a changeset I would like to ask the floating point experts among you if that is the right thing to do.

regards

Thorsten

Thorsten Meyer <tmeyier>In charge of this item.

 

(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 (Updated the item)
  • -unavailable- added by tmeyier (Submitted the item)
  • -unavailable- added by tmeyier
  •  

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

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 17 Apr 2009 08:07:56 PM UTCtmeyierStatusReady For Test=>Fixed
      Assigned tohighegg=>tmeyier
      Open/ClosedOpen=>Closed
    Thu 16 Apr 2009 06:24:31 AM UTChigheggStatusNeed Info=>Ready For Test
      Assigned totmeyier=>highegg
    Wed 15 Apr 2009 05:16:36 PM UTCtmeyierCarbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1