= #JxnPortable/docs/programmer_examples/demos/BigIntegerAlgebra_Demo.jxn

! Wrapper BigIntegerAlgebra for java.math.BigInteger allows mixed arithmetic with int and long operands

a = @BigIntegerAlgebra("3")
 = 3 (BigIntegerAlgebra)
b = @BigIntegerAlgebra(7)
 = 7 (BigIntegerAlgebra)

-a
 = -3 (BigIntegerAlgebra)
a b
 = 21 (BigIntegerAlgebra)
a - b
 = -4 (BigIntegerAlgebra)
a + b
 = 10 (BigIntegerAlgebra)
b / a
 = 2 (BigIntegerAlgebra)
b % a
 = 1 (BigIntegerAlgebra)
a^150
 = 369988485035126972924700782451696644186473100389722973815184405301748249 (BigIntegerAlgebra)

! Fibonacci numbers:
n = 1000
 = 1000 (int)
f0 = BIG0; f1 = BIG1; JxnLoop.repeat( $this, "", n-1, "f2 = f1 + f0; f0 = f1; f1 = f2;" )
 = 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875 (BigIntegerAlgebra)
$.doubleValue()
 = 4.3466557686937455E208 (double)

! wrapper BigIntegerAlgebra supports mixed arithmetic:
a 5
 = 15 (BigIntegerAlgebra)
2 + b
 = 9 (BigIntegerAlgebra)
ia = { 2, 3, 5 }
 = { 2, 3, 5 } (int[3])
a ia
 = { 6, 9, 15 } (BigIntegerAlgebra[3])
ia + b
 = { 9, 10, 12 } (BigIntegerAlgebra[3])
 
 
#function factorial( n )  ! = 1 * 2 * 3 * ... * n
   $i = 2; $result = @BigIntegerAlgebra(1)  ! local variables
   #while le( $i, n )
      $result *= $i
      $i += 1
   #endwhile
   #return $result
#endfunction

factorial(5)
 = 120 (BigIntegerAlgebra)
factorial(10)
 = 3628800 (BigIntegerAlgebra)
factorial(20)
 = 2432902008176640000 (BigIntegerAlgebra)
factorial(100)
 = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 (BigIntegerAlgebra)