I think you mean "finds elements of a list which would be
representable exactly as either integers or booleans". Typically, your
list will be all floating point numbers. But, also, I do not think you
want to exclude 1 nor 0.

This boils down to a test for fractionality with a range test.

In many languages, this sort of testing is made more convenient with
constants representing the largest and smallest possible integers. J
currently does not have that. But we can define our own:

MAXINT=: #.1#~31+32*IF64
MININT=: <:-MAXINT

Now all we have to do is enhance your fractionality test with a range test.

isinteger=: (=<.) * <:&MAXINT * >:&MININT

Which gives us:

   isinteger 1 2.5 __ 3 4.5 6
1 0 0 1 0 1

That said, I would want to talk about complex numbers and rational and
extended precision numbers before I tried to implement an
'isfloating'.  This fractionality test throws a domain error for
complex values, and technically all extended precision values are
integers, even after a floor operation (though you can defeat this by
appending an infinity to the list).

Thanks,

-- 
Raul

On Sun, Aug 2, 2020 at 8:24 AM Skip Cave <s...@caveconsulting.com> wrote:
>
> What I'm really looking for, is a verb that finds integers in a list:
>
> datatype 2.5
>
> floating
>
> datatype 3
>
> integer
>
> datatype __
>
> floating
>
>
> So J considers __ as "floating"
>
>
>  So I want a verb "isinteger" that marks the integers in a vector, where __
> is in the list, and is considered floating:
>
>   isinteger 1 2.5 __ 3 4.5 6
> 1 0 0 1 0 1
>
> And maybe the inverse also:
>
> isfloating 1 2.5 __ 3 4.5 6
>
> 0 1 1 0 1 0
>
>
> My (=<,) doesn't do it:
>
> (=<.)1 2.5 __ 3 4.5 6
>
> 1 0 1 1 0 1
>
>
> So what would "isinteger" look like?
>
>
> Skip
>
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Sun, Aug 2, 2020 at 1:44 AM Skip Cave <s...@caveconsulting.com> wrote:
>
> > I use the (=<.) verb to find integers in a list:
> >
> >
> > * (=<.)1 2.5 2.7 3 4.5 6*
> >
> > *1 0 0 1 0 1*
> >
> > * (#~(=<.))1 2.5 2.7 3 4.5 6*
> >
> > *1 3 6*
> >
> > I ran across an interesting result when infinity is in the list:
> >
> > * (=<.)1 2.5 __ 3 4.5 6*
> >
> > *1 0 1 1 0 1*
> >
> > * (#~(=<.))1 2.5 __ 3 4.5 6*
> >
> > *1 __ 3 6*
> >
> >
> > So J is saying that the floor of infinity is infinity (and the ceiling of
> > infinity is also infinity). Since infinity is not a number, it would seem
> > that an error should be generated when taking the floor of infinity, or
> > perhaps NAN, or a zero? In any case, this messes up my nice integer-finding
> > verb. Is the\re a mathematical justification for defining the floor of
> > infinity to be infinity?
> > https://math.stackexchange.com/questions/981708/limit-of-floor-function-when-x-goes-infinity
> >
> >
> > Skip
> >
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to