Extension to intmin/intmax to accept integer values?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extension to intmin/intmax to accept integer values?

Rik-4
The current intmin/intmax accept a string as an input.  For example,

intmax ("uint8")
=> 255

How useful would it be to accept an actual integer class variable?  I could
see situations where one might have created an integer variable of some
sort, or maybe it was someone else's code so you have even less of an idea,
and you would like to know something about the limits.  Sample code

x = uint8 (3);
... lots of intervening code ...
intmax (x)
=> 255

Of course, one way to do this would simply be to get the class of the
variable and feed it to intmax.

class (x)
=> uint8
intmax (class (x))
=> 255

But, it still feels nicer to just query the variable directly.  If this is
of interest it isn't very hard to had to bitfcns.cc.  It would be an Octave
extension beyond Matlab's behavior.

--Rik


Reply | Threaded
Open this post in threaded view
|

Re: Extension to intmin/intmax to accept integer values?

Carnë Draug
On Sat, 10 Nov 2018 at 15:49, Rik <[hidden email]> wrote:

>
> The current intmin/intmax accept a string as an input.  For example,
>
> intmax ("uint8")
> => 255
>
> How useful would it be to accept an actual integer class variable?  I could
> see situations where one might have created an integer variable of some
> sort, or maybe it was someone else's code so you have even less of an idea,
> and you would like to know something about the limits.  Sample code
>
> x = uint8 (3);
> ... lots of intervening code ...
> intmax (x)
> => 255
>
> Of course, one way to do this would simply be to get the class of the
> variable and feed it to intmax.
>
> class (x)
> => uint8
> intmax (class (x))
> => 255
>
> But, it still feels nicer to just query the variable directly.  If this is
> of interest it isn't very hard to had to bitfcns.cc.  It would be an Octave
> extension beyond Matlab's behavior.

This seems like a very nice addition.  I don't think I ever just
wanted to get intmax/intmin for a specific class, it's always the
intmax/min of a passed argument.  Grepping for intmax on the image
package and the core image functions, confirms the same.

~
carandraug

Reply | Threaded
Open this post in threaded view
|

Re: Extension to intmin/intmax to accept integer values?

Rik-4
On 11/10/2018 11:28 AM, Carnë Draug wrote:

> On Sat, 10 Nov 2018 at 15:49, Rik <[hidden email]> wrote:
>> The current intmin/intmax accept a string as an input.  For example,
>>
>> intmax ("uint8")
>> => 255
>>
>> How useful would it be to accept an actual integer class variable?  I could
>> see situations where one might have created an integer variable of some
>> sort, or maybe it was someone else's code so you have even less of an idea,
>> and you would like to know something about the limits.  Sample code
>>
>> x = uint8 (3);
>> ... lots of intervening code ...
>> intmax (x)
>> => 255
>>
>> Of course, one way to do this would simply be to get the class of the
>> variable and feed it to intmax.
>>
>> class (x)
>> => uint8
>> intmax (class (x))
>> => 255
>>
>> But, it still feels nicer to just query the variable directly.  If this is
>> of interest it isn't very hard to had to bitfcns.cc.  It would be an Octave
>> extension beyond Matlab's behavior.
> This seems like a very nice addition.  I don't think I ever just
> wanted to get intmax/intmin for a specific class, it's always the
> intmax/min of a passed argument.  Grepping for intmax on the image
> package and the core image functions, confirms the same.

I added support for this feature to intmin/intmax in this changeset
(https://hg.savannah.gnu.org/hgweb/octave/rev/df3f2e119944).  I also
simplified any instances of intmax (class (x)) in the scripts/ directory to
use the new calling form.

For good measure, I also added the ability to query a variable to flintmax
in this cset (https://hg.savannah.gnu.org/hgweb/octave/rev/afc3d1da58e5).

--Rik