octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #33168] abs function in octave c++ API convert


From: foehler
Subject: [Octave-bug-tracker] [bug #33168] abs function in octave c++ API converting standard C++ type to int
Date: Tue, 26 Apr 2011 23:14:31 +0000
User-agent: Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0

URL:
  <http://savannah.gnu.org/bugs/?33168>

                 Summary: abs function in octave c++ API converting standard
C++ type to int
                 Project: GNU Octave
            Submitted by: foehler
            Submitted on: Tue 26 Apr 2011 23:14:30 GMT
                Category: Libraries
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Improvement/Optimization
                  Status: None
             Assigned to: None
         Originator Name: foehler
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.4.0
        Operating System: GNU/Linux

    _______________________________________________________

Details:

The abs function (loaded somewhere in <octave/oct.h>) converts to int as there
is no definition of 'abs' using double but only int-like var. 


#include <octave/oct.h>
#include <cmath>

DEFUN_DLD (abs_test, args,,
  "Test abs")
{
double test=args(0).double_value();

octave_stdout<<test<<" :octave abs\t"<<abs(test)<<"\n";
octave_stdout<<test<<" :cmath  abs\t"<<std::abs(test)<<"\n";

return octave_value_list ();
}
+verbatim

In octave
+verbatim
abs_test(-1.3)
+verbatim

This might be the correct behaviour considering the definition of abs  here
<http://octave.sourceforge.net/doxygen/html/functions_func_0x61.html#index_a>,
which doesn't accept double, and the other definition of abs here
<http://octave.sourceforge.net/doxygen/html/pr-output_8cc.html> which seems to
use only int-like var as input.


Defining double variable as 1x1 NDarray  (or similar) is not very convenient.
If the 'abs' behaviour can not be changed, could a warning be printed at
compilation against this behaviour (and suggesting the cmath version)

However I am very far from understanding C++ API and I could be missing an
important bit.

Could someone confirm this ?


Thanks,
 Fab. 

(octave 3.4.0 compiled from source)





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?33168>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]