Package org.jscience.mathematics.number

Examples of org.jscience.mathematics.number.LargeInteger


  @SuppressWarnings("rawtypes")
  @Override
  public ParseResult parse(final TokenList tokens, final int templatePos) {
   
    final String op = (String) tokens.get(templatePos);
    final LargeInteger input = (LargeInteger) tokens.get(templatePos + 1);
    Number result = null;
   
    if(op.equals("factorial")){
      //System.out.println("INput is: "+input);
     
      if(input.isLessThan(LargeInteger.valueOf(20)) && input.isGreaterThan(LargeInteger.ZERO)){
        result = LargeInteger.valueOf(factorial(input.longValue()));
       
        return ParseResult.success(tokens.replaceWithTokens(templatePos, templatePos+template.size(), result));
      }
     
     
View Full Code Here


            Real sqrt2 = two.sqrt();
            System.out.println("sqrt(2)   = " + sqrt2);
            System.out.println("Precision = " + sqrt2.getPrecision()
                    + " digits.");

            LargeInteger dividend = LargeInteger.valueOf("3133861182986538201");
            LargeInteger divisor = LargeInteger.valueOf("25147325102501733369");
            Rational rational = Rational.valueOf(dividend, divisor);
            System.out.println("rational  = " + rational);

            ModuloInteger m = ModuloInteger.valueOf("233424242346");
            LocalContext.enter(); // Avoids impacting others threads.
View Full Code Here

        System.out.println();
        System.out.println("LargeInteger (StackContext) versus BigInteger");
        BigInteger big = BigInteger.probablePrime(1024, new Random());
        byte[] bytes = big.toByteArray();
        LargeInteger large = LargeInteger.valueOf(bytes, 0, bytes.length);

        System.out.print("LargeInteger (1024 bits) addition: ");
        startTime();
        for (int i = 0; i < 1000; i++) {
            StackContext.enter();
            for (int j = 0; j < results.length; j++) {
                results[j] = large.plus(large);
            }
            StackContext.exit();
        }
        endTime(1000 * results.length);

        System.out.print("LargeInteger (1024 bits) multiplication: ");
        startTime();
        for (int i = 0; i < 100; i++) {
            StackContext.enter();
            for (int j = 0; j < results.length; j++) {
                results[j] = large.times(large);
            }
            StackContext.exit();
        }
        endTime(100 * results.length);

 
View Full Code Here

TOP

Related Classes of org.jscience.mathematics.number.LargeInteger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.