help-octave
[Top][All Lists]
Advanced

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

Re: oct file ; problem with argument checking


From: Mike Miller
Subject: Re: oct file ; problem with argument checking
Date: Fri, 22 Sep 2017 08:21:01 -0700
User-agent: NeoMutt/20170609 (1.8.3)

On Fri, Sep 22, 2017 at 13:52:20 +0200, arnaud Lejeune wrote:
> it works with int8(2) but isn't any member of "octave_value" that recognizes
> "2" as an integer when the user writes
> [x,y] = toto( 2 )

It sounds like want your function to accept floating point values that
happen to have integer values, is that correct? And you want to issue an
error when the floating point value is not exacty an integer?

If that's the case then you want to do something like the following

    double a = args(0).scalar_value ();
    if (a != std::floor (a))
      error ("myfunc: A must be an integer scalar value");
    int value = static_cast<int> (a);

If you are working with an older version of Octave, I think you'll need
a return statement after the error call.

-- 
mike

Attachment: signature.asc
Description: PGP signature


reply via email to

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