Seeing as J currently only has 32-bit and 64-bit implementations, I
would be inclined to go with
MAXINT =: ->: MININT =: _2 <.@^ <: +:^:IF64 32

The auto-detection is cool though; you can tighten it up a bit by
working with negative numbers again.
MAXINT =: ->: MININT =: <.-: +:^:(4>:3!:0)^:_ ]_1

Marshall

On Wed, Feb 03, 2016 at 07:30:22PM -0500, Raul Miller wrote:
> On Wed, Feb 3, 2016 at 5:19 PM, Marshall Lochbaum <[email protected]> 
> wrote:
> > I sent an email about the problem of coercion to integer a month ago; my
> > recommendation was fl:
> >
> > MAX =: ->: MIN =: _2 <.@^ 63
> > fl =: ((MAX*-.@]) + [: <. MIN>.*) <:&MAX
> 
> Note that this won't work right on 32 bit J. The values for MAX and
> MIN would be wrong. Nor would it do the right thing on a 128 bit J
> (for example, if anyone ever cares to implement something like that
> for IBM 370). That said, my earlier MAXINT and MININT don't work right
> on 32 bit J, either. So here's fixed (and slightly simpler) version of
> those definitions:
> 
> MININT=: _1-MAXINT=: +/".":x:}:+:^:(4>:3!:0)^:a:1
> 
> These are the same values as your MAX and MIN on 64 bit J, but these
> definitions also work on 32 bit J, and hypothetically speaking would
> also work for a 128 bit J.
> 
> That said, there's also a problem with your fl, on current 64 bit J,
> which is related to what you were posting about earlier:
> 
>    3!:0 fl MAX-432.1
> 8
>    3!:0 fl fl fl MAX-432.1
> 8
> 
> Here, a positive floating point value which is smaller than MAX does
> not get converted to integer.
> 
> -- 
> Raul
> ----------------------------------------------------------------------
> 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