|
From: | Julien Bect |
Subject: | Re: Unnecessary initialization in octave_matrix::double_value ? |
Date: | Sun, 28 Aug 2016 16:34:12 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.1.0 |
Le 28/08/2016 à 16:17, John W. Eaton a écrit :
On 08/28/2016 04:12 AM, Julien Bect wrote:Hi all, I have a (probably naive) C++ question concerning the implementation of octave_matrix::double_value (). It is currently written like this: double octave_matrix::double_value (bool) const { double retval = lo_ieee_nan_value (); if (is_empty ()) err_invalid_conversion ("real matrix", "real scalar"); warn_implicit_conversion ("Octave:array-to-scalar", "real matrix", "real scalar"); retval = matrix(0, 0); return retval; } I don't understand the point of initializing retval with the result of lo_ieee_nan_value (). Would it be correct to simply write: double octave_matrix::double_value (bool) const { if (is_empty ()) err_invalid_conversion ("real matrix", "real scalar"); warn_implicit_conversion ("Octave:array-to-scalar", "real matrix", "real scalar"); return matrix (0, 0); }You are right, that initialization is no longer needed. It is left over from when the error function did not throw an exception but just printed a message and set a global warning state, then returned. So in the old days the function would always return something. A NaN was better than undefined. Although much of the work has been done to adapt to the new way that error works, there are still many small things like this to clean up.
Ok, I will prepare a patch for ::float_value() and ::double_value().
[Prev in Thread] | Current Thread | [Next in Thread] |