bugGNU Octave - Bugs: bug #46658, fzero with single precision args...


bug #46658: fzero with single precision args fails to terminate

Submitter:  Ceral Paquet <octavebugs>
Submitted:  Thu 10 Dec 2015 04:11:56 PM UTC
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.0.0 Operating System:  * GNU/Linux
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


( Jump to the original submission )

Mon 18 Jan 2016 06:23:19 PM UTC, comment #6: 

I made the change to fzero to correctly choose a stopping tolerance on the stable branch (http://hg.savannah.gnu.org/hgweb/octave/rev/323e92c4589f).  Even though there were no problems reported, I also updated the other scripts in the optimization directory to correctly choose a stopping tolerance (http://hg.savannah.gnu.org/hgweb/octave/rev/52af4092f863).

Closing report.

Rik <rik5>
Project Administrator
Fri 11 Dec 2015 09:51:32 AM UTC, comment #5: 

Nice. Works for me with all combos of single and double.

I also looked at


There are a couple of places where class(x0) is used but when I tested them with with similar problems there was no problem with any combination of single/double.

fminunc.m:  macheps = eps (class (x0));
fsolve.m:  macheps = eps (class (x0));

The TolX and TolFun are hardcoded (to 1e-7).

Ceral Paquet <octavebugs>
Thu 10 Dec 2015 10:08:42 PM UTC, comment #4: 

fzero is looking only at the class of x0 to decide what eps to use.  It's pretty simple to extend that to include looking at the results of the function evaluation.  The function fzero is written in fzero.m which means you can go ahead and change it quite easily.

I made a quick attempt which seems to work for me.  See the attached cset.

(file #35694)

Rik <rik5>
Project Administrator
Thu 10 Dec 2015 06:01:53 PM UTC, comment #3: 

Problem also goes away if fun returns a double. So, basically x0 and the return value of func need to be the same class.

Ceral Paquet <octavebugs>
Thu 10 Dec 2015 05:43:04 PM UTC, comment #2: 

Seems the problem goes away if the initial estimate is a single too. Perhaps eps is being derived from the initial estimate, whereas it should be eps('single') if any of the inputs is single.

Ceral Paquet <octavebugs>
Thu 10 Dec 2015 04:23:14 PM UTC, comment #1: 

Setting TolX with

optimset ("TolX", 2 * eps (class (x)))

works for me.

Matlab definitely documents that the default TolX value is eps("double"), which is what Octave's fzero is using.

Mike Miller <mtmiller>
Project Administrator
Thu 10 Dec 2015 04:11:56 PM UTC, original submission:  

The code below does not terminate when data are in single precision although it works fine with doubles. Matlab works in both instances.

Passing opts = optimset('TolX',class(x)) did not fix it. That uses 1.16e-7 rather than 2.2e-16. It seems to need even lower precision, like 1e-6, to finish.

% data
x = -20:20;
y = [


% these prevent fzero from terminating
x = single(x);
y = single(y);

% find FWHM
myfunc = @(x,y,pt) interp1(x,y,pt,'spline') - 0.5;

pt0 = 5;
pt = fzero(@(pt)myfunc(x,y,pt),pt0)

Ceral Paquet <octavebugs>


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

Attach Files:

Attached Files
file #35694:  fzero.cset added by rik5 (1KiB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by octavebugs (Submitted the item)

    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 project members can vote.





    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-01-18 rik5 Item GroupPerformance Incorrect Result
        StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2015-12-10 rik5 Attached File- Added fzero.cset, #35694
        StatusConfirmed Patch Submitted
    2015-12-10 mtmiller CategoryNone Octave Function
        Item GroupNone Performance
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.9