bugGNU Octave - Bugs: bug #60497, Unable to pass int64 values to oct...

 
 

bug #60497: Unable to pass int64 values to oct interface reliably

Submitted by:  Pantxo Diribarne <pantxo>
Submitted on:  Sun 02 May 2021 01:41:57 PM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

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

 

Sun 02 May 2021 09:03:24 PM UTC, comment #2: 

I haven't checked to be sure, but I suspect that the int64_value function is something that existed before integer values were added to the octave_value data type.  We should probably look at deprecating and removing all the functions that are defined with the INT_CONV_MEDTHOD macro in ov-base.cc short_value, ushort_value, int_value, uint_value, long_value, ulong_value, int64_value, uint64_value.

John W. Eaton <jwe>
Project Administrator
Sun 02 May 2021 05:40:16 PM UTC, comment #1: 

OK I cannot say that I understand the logic, but at least I found a way to have it work using "int64_scalar_value" rather than "int64_value". The latter is a generic "static_cast<int64> (octave_value::double_value ())" and leads to corrupted data due to the intermediate conversion to double.

Now I wonder why we need both methods?

Pantxo Diribarne <pantxo>
Project Member
Sun 02 May 2021 01:41:57 PM UTC, original submission:  

Consider the following oct file that just tries to parse an int64 argument and show it value:

DEFUN_DLD(show_int64, args, nargout,
          "-*- texinfo -*-\n\
@deftypefn {} {@var{out} =} ping_int64 (@var{in})\n\
@seealso{}\n\
@end deftypefn")
{
  int nargin = args.length ();

  if (nargin != 1)
    print_usage ();

  int64_t out = args(0).xint64_value ("IN should be a scalar int64 val");

  octave_stdout << out << std::endl;

  return ovl ();
}

Here is what I obtain when using this function:

octave:1> a = intmax ("int64")
a = 9223372036854775807
octave:2> show_int64 (a)
-9223372036854775808

See related discussion on the discourse forum:

https://octave.discourse.group/t/how-to-safely-use-int64-type/1096

Pantxo Diribarne <pantxo>
Project Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #51356:  show_int64.cc added by pantxo (1KiB - text/x-c++src)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by pantxo (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-05-02 pantxo Attached File- => Added show_int64.cc, #51356

    Back to the top


    Powered by Savane 3.6