Actually, I don't care about coercing floating point to integer - just
boolean to integer. And, this is just a model. So:

MAXINT=: +/1,(#~1-2&|)".":x:+:^:(4>:3!:0)^:a:1
MININT=: _1-MAXINT

setype=:dyad define
  select. x
    case. 1 do. 0~:y
    case. 4 do. <.MININT>.y<.MAXINT
    case. 8 do. y<._
    case. 64 do. <.x:y
    case. 128 do. (1r2*2r1)*x:y
    case. do. throw.
  end.
)

BIDZXQ=: adverb define
  u y
:
  type=. x >.&(3!:0) y
  x u&(type&setype) y
)

Known problems:
* setype fails for type 4 for some values (like: MAXINT-432.1)
* does not currently support literal, boxed nor sparse types
* not tested cross-platform
* maybe could use a different name

Example use:
   1.1 + BIDZXQ 1r2
8r5

-- 
Raul

On Wed, Feb 3, 2016 at 2:39 PM, Raul Miller <[email protected]> wrote:
> I think, in this case, that we are working against the language
> definition. That tends to introduce quirks and other problems into the
> language.
>
> Specifically, I think we would be working against
> http://www.jsoftware.com/help/dictionary/dictg.htm and the table
> introduced by the phrase "Dyadic verbs (e.g. + - * % , = <) that
> require argument type conversions".
>
> So, rather than introducing a special case which requires inspection
> of arguments, maybe the right thing to do is to define an adverb which
> implements a different type conversion table on behalf of whatever
> verb it's working with?
>
> That said, I set out to write such a thing, and got stalled when
> trying to figure out how reliably and efficiently coerce a floating
> point array to integer type.
>
> Specifically:
>
> MAXINT=: +/1,(#~1-2&|)".":x:+:^:(4>:3!:0)^:a:1
> MININT=: _1-MAXINT
>
>    3!:0 MAXINT,MININT
> 4
>    3!:0 <.MININT>.( MAXINT+0.01)<.MAXINT-1
> 8
>
> Basically, I'm not sure how to deal with this existing quirk:
>
>    x:MAXINT
> 9223372036854775807
>    x:( MAXINT-0.01)<.MAXINT-511
> 9223372036854775808
>    9!:14''
> j804/j64/darwin/release/commercial/www.jsoftware.com/2015-12-21 18:06:25
>
> Any suggestions?
>
> Thanks,
>
> --
> Raul
>
>
> On Wed, Feb 3, 2016 at 2:02 PM, Dan Bron <[email protected]> wrote:
>> I know we have yet to organize a formal process for building and 
>> disseminating a community-driven implementation of J, but in anticipation of 
>> that day’s arrival, perhaps we can start collecting community-driven 
>> proposals for enhancements?
>>
>> One such enhancement could be special code that detects whether the argument 
>> to an arithmetic dyad is the scalar _ (or __ or _.) and if so, avoids 
>> demoting the other argument to double if it’s already extended or rational.
>>
>> I have other ideas too. But maybe we should collect them on the Wiki?
>>
>> -Dan
>>
>>
>>> On Feb 2, 2016, at 9:12 PM, Henry Rich <[email protected]> wrote:
>>>
>>> No, extendeds promote to float on mixed operations.
>>>
>>> Henry Rich
>>>
>>> On 2/2/2016 9:09 PM, 'Pascal Jasmin' via Programming wrote:
>>>>    9223372036854736345 <. _
>>>> 9.22337e18
>>>>
>>>> result is a double.  <. double is the closest integer it can find.
>>>>
>>>> this seems like a problem though:
>>>>
>>>>
>>>>     9223372036854736345x <. _
>>>> 9.22337e18
>>>>
>>>>
>>>>
>>>> ----- Original Message -----
>>>> From: Henry Rich <[email protected]>
>>>> To: Programming forum <[email protected]>
>>>> Sent: Tuesday, February 2, 2016 9:05 PM
>>>> Subject: [Jprogramming] When a <. _ is less than a
>>>>
>>>> I'm stepping up to the world of 64-bit integers, and stepping into 
>>>> cowflops.
>>>>
>>>> This took me quite a while:
>>>>
>>>>      <. 9223372036854736345 <. _
>>>>
>>>> 9223372036854735872
>>>>
>>>>
>>>> See that?  Take the minimum of (number) and (infinity), and the result
>>>> is less than (number)!
>>>>
>>>> Yes, I understand why it happens.  Now I do.  Be warned.
>>>>
>>>> Henry Rich
>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> ----------------------------------------------------------------------
>> 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