I get the same answer with non reversed mul as with mul.  64 bit windows.  On 
32bit I get your same result.  On 64 bit though my result is not converted to 
float:

   P&|@*/ mul
39355325


The issue is that on 32 bit, the range of numbers you are using is close enough 
to get converted to float.  This fixes it on 32 bit.

P=:9x+1e9
mul=.1+pr (P&|@^) 2x (P&|@*) pw 


P&|@*/ |. mul 
39355325 
P&|@*/  mul 
39355325 




________________________________
From: Andrew Nikitin <[email protected]>
To: J programming <[email protected]> 
Sent: Friday, July 31, 2015 12:16 PM
Subject: [Jprogramming] multiplication bug


i am trying to multiply several integers modulo small prime number here and 
fail at that.

------------------------ 

   NB. highest power of prime x that divides !y

   pffact=:([: +/ ] <.@% [ ^ 1 + [: i. <.@^.)

   P=:9+1e9

   pw=.1e9 pffact">~ pr=.p:i.240 NB. first few primes and their powers

   1 p: P NB. P is prime

1
   datatype P
integer

------------------------ 
here is a list of integers I am trying to multiply
------------------------ 

   mul=.1+pr (P&|@^) 2 (P&|@*) pw
   datatype mul
integer

------------------------ 
And here is what happens when I actually multiply them:
------------------------ 

      P&|@*/ mul
0

------------------------
which is not the right answer
------------------------ 

      P&|@*/ |.mul
3.90562e7

------------------------ 


                          
----------------------------------------------------------------------
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