bugGNU Octave - Bugs: bug #33168, abs function in octave c++ API...

 
 

bug #33168: abs function in octave c++ API converting standard C++ type to int

Submitted by:  foehler <foehler>
Submitted on:  Tue 26 Apr 2011 11:14:30 PM UTC  
 
Category: LibrariesSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Other
Status: InvalidAssigned to: None
Originator Name: foehlerOpen/Closed: Closed
Release: 3.4.0Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Thu 05 Sep 2013 01:37:08 AM UTC, comment #2:

This is not an Octave bug, this is simply confusion about C versus C++ functions. The plain abs function is from the C math library and is defined as "int abs(int)". To get a double-precision absolute value, use either std::abs as you have shown below or use the C fabs function.

Mike Miller <mtmiller>
Project Administrator
Tue 26 Apr 2011 11:23:30 PM UTC, comment #1:

(follow up from previous post)

+verbatim
#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

This is the correct behaviour, considering the definition of 'abs'
here which only accept int-like var, and the definition of 'abs' here where only the octave type are allowed.

Defining double as 1x1 NDArray is not very convenient. If octave 'abs' can not accept double, should a warning be issued at compilation ( and suggest the <cmath> version ?)

However my C++ skill are limited and I am far from understanding the C++ API. Could someone confirm this ?

Kind regard,
Fabrice

foehler <foehler>
Tue 26 Apr 2011 11:14:30 PM UTC, original submission:

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.

foehler <foehler>

 

(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 mtmiller (Posted a comment)
  • -unavailable- added by rik5 (Updated the item)
  • -unavailable- added by foehler (Submitted the item)
  •  

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

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 05 Sep 2013 01:37:08 AM UTCmtmillerStatusConfirmed=>Invalid
      Open/ClosedOpen=>Closed
    Mon 27 Feb 2012 05:59:02 PM UTCrik5Item GroupPerformance=>Other
      StatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1