Re: [Jprogramming] A clever way to find the maximum possible integer

2016-03-19 Thread Roger Shepherd
What should I read to anticipate the effects if 33 b. and similar verbs on
extended integers?
Thanks for any pointers.


On Monday, March 14, 2016, Marshall Lochbaum  wrote:

> I just stumbled across the following snippet. Platform independent,
> constant time (for those with 2048-bit processors, naturally), and only
> nine characters!
>
>33 b.~ _1
> 9223372036854775807
>
> The verb (33 b.), not often used in J, is the unsigned shift operator,
> like C's (<<). When the left operand x is positive, it has the same
> effect as multiplying y by (2^x). If x is negative and y is positive, it
> is the same as division by (2^-x) followed by rounding down. However, if
> x and y are both negative, then y is shifted as an unsigned integer: all
> of its bits are moved right by (|x), and (|x) zeros are added on the
> left.
>
> If y is _1, then its two's complement representation is all ones.
> Shifting right by one leaves a number represented by a zero and then all
> ones--the largest possible positive integer.
>
> If you want both the maximum and minimum integers:
> MIN_INT =: <:- MAX_INT =: 33 b.~ _1
>
> Marshall
> --
> For information about J forums see http://www.jsoftware.com/forums.htm



-- 
Sent from Gmail Mobile
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] A clever way to find the maximum possible integer

2016-03-19 Thread Pascal Jasmin
They fail.


This library uses openssl bindings (available on all platforms and ships with 
recent Js)


https://github.com/Pascal-J/BN-openssl-bindings-for-J

I don't remember if I implemented all boolean functions but it's 
straightforward to define any missing ones using one as template.

The other approach is to represent large integers as polynomials (arrays of 32 
or 64 bit or 10^x base numbers), an approach which I've previously posted to 
forum.



From: Roger Shepherd 
To: "programm...@jsoftware.com"  
Sent: Wednesday, March 16, 2016 7:41 AM
Subject: Re: [Jprogramming] A clever way to find the maximum possible integer


What should I read to anticipate the effects if 33 b. and similar verbs on
extended integers?
Thanks for any pointers.


On Monday, March 14, 2016, Marshall Lochbaum  wrote:

> I just stumbled across the following snippet. Platform independent,
> constant time (for those with 2048-bit processors, naturally), and only
> nine characters!
>
>33 b.~ _1
> 9223372036854775807
>
> The verb (33 b.), not often used in J, is the unsigned shift operator,
> like C's (<<). When the left operand x is positive, it has the same
> effect as multiplying y by (2^x). If x is negative and y is positive, it
> is the same as division by (2^-x) followed by rounding down. However, if
> x and y are both negative, then y is shifted as an unsigned integer: all
> of its bits are moved right by (|x), and (|x) zeros are added on the
> left.
>
> If y is _1, then its two's complement representation is all ones.
> Shifting right by one leaves a number represented by a zero and then all
> ones--the largest possible positive integer.
>
> If you want both the maximum and minimum integers:
> MIN_INT =: <:- MAX_INT =: 33 b.~ _1
>
> Marshall
> --
> For information about J forums see http://www.jsoftware.com/forums.htm



-- 
Sent from Gmail Mobile

--
For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] A clever way to find the maximum possible integer

2016-03-19 Thread Marshall Lochbaum
To clarify, the arguments are converted to normal integers, if possible.
If they are too large, the domain error that Pascal is referring to
results. If they are can be converted, then the boolean function is
applied to the integers to give a normal integer result.

The same holds for floats and complex numbers: if the arguments are
tolerantly equal to integers, then the function is executed on those
integers, and if not it yields a domain error.

Left and right shift are included in Pascal's library--that's good to
know about! There is no logical (as opposed to arithmetic) right shift
on extended integers since there is no last bit on the left to replace
with a zero.

Marshall

On Wed, Mar 16, 2016 at 01:17:20PM +, Pascal Jasmin wrote:
> They fail.
> 
> 
> This library uses openssl bindings (available on all platforms and ships with 
> recent Js)
> 
> 
> https://github.com/Pascal-J/BN-openssl-bindings-for-J
> 
> I don't remember if I implemented all boolean functions but it's 
> straightforward to define any missing ones using one as template.
> 
> The other approach is to represent large integers as polynomials (arrays of 
> 32 or 64 bit or 10^x base numbers), an approach which I've previously posted 
> to forum.
> 
> 
> 
> From: Roger Shepherd 
> To: "programm...@jsoftware.com"  
> Sent: Wednesday, March 16, 2016 7:41 AM
> Subject: Re: [Jprogramming] A clever way to find the maximum possible integer
> 
> 
> What should I read to anticipate the effects if 33 b. and similar verbs on
> extended integers?
> Thanks for any pointers.
> 
> 
> On Monday, March 14, 2016, Marshall Lochbaum  wrote:
> 
> > I just stumbled across the following snippet. Platform independent,
> > constant time (for those with 2048-bit processors, naturally), and only
> > nine characters!
> >
> >33 b.~ _1
> > 9223372036854775807
> >
> > The verb (33 b.), not often used in J, is the unsigned shift operator,
> > like C's (<<). When the left operand x is positive, it has the same
> > effect as multiplying y by (2^x). If x is negative and y is positive, it
> > is the same as division by (2^-x) followed by rounding down. However, if
> > x and y are both negative, then y is shifted as an unsigned integer: all
> > of its bits are moved right by (|x), and (|x) zeros are added on the
> > left.
> >
> > If y is _1, then its two's complement representation is all ones.
> > Shifting right by one leaves a number represented by a zero and then all
> > ones--the largest possible positive integer.
> >
> > If you want both the maximum and minimum integers:
> > MIN_INT =: <:- MAX_INT =: 33 b.~ _1
> >
> > Marshall
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> 
> 
> 
> -- 
> Sent from Gmail Mobile
> 
> --
> 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

Re: [Jprogramming] A clever way to find the maximum possible integer

2016-03-14 Thread Raul Miller
Nice.

-- 
Raul


On Mon, Mar 14, 2016 at 11:22 PM, Marshall Lochbaum
 wrote:
> I just stumbled across the following snippet. Platform independent,
> constant time (for those with 2048-bit processors, naturally), and only
> nine characters!
>
>33 b.~ _1
> 9223372036854775807
>
> The verb (33 b.), not often used in J, is the unsigned shift operator,
> like C's (<<). When the left operand x is positive, it has the same
> effect as multiplying y by (2^x). If x is negative and y is positive, it
> is the same as division by (2^-x) followed by rounding down. However, if
> x and y are both negative, then y is shifted as an unsigned integer: all
> of its bits are moved right by (|x), and (|x) zeros are added on the
> left.
>
> If y is _1, then its two's complement representation is all ones.
> Shifting right by one leaves a number represented by a zero and then all
> ones--the largest possible positive integer.
>
> If you want both the maximum and minimum integers:
> MIN_INT =: <:- MAX_INT =: 33 b.~ _1
>
> Marshall
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

[Jprogramming] A clever way to find the maximum possible integer

2016-03-14 Thread Marshall Lochbaum
I just stumbled across the following snippet. Platform independent,
constant time (for those with 2048-bit processors, naturally), and only
nine characters!

   33 b.~ _1
9223372036854775807

The verb (33 b.), not often used in J, is the unsigned shift operator,
like C's (<<). When the left operand x is positive, it has the same
effect as multiplying y by (2^x). If x is negative and y is positive, it
is the same as division by (2^-x) followed by rounding down. However, if
x and y are both negative, then y is shifted as an unsigned integer: all
of its bits are moved right by (|x), and (|x) zeros are added on the
left.

If y is _1, then its two's complement representation is all ones.
Shifting right by one leaves a number represented by a zero and then all
ones--the largest possible positive integer.

If you want both the maximum and minimum integers:
MIN_INT =: <:- MAX_INT =: 33 b.~ _1

Marshall
--
For information about J forums see http://www.jsoftware.com/forums.htm