Login   Register  
Icontem

File: example.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Gábor Martini  >  bzPrime  >  example.js  >  Download  
File: example.js
Role: Example script
Content type: text/plain
Description: Calculations example
Class: bzPrime
Perform calculations prime numbers
Author: By
Last change:
Date: 2012-10-15 06:40
Size: 1,503 bytes
 

Contents

Class file image Download
    bzp = new bzPrime();

/* Integer factorization
    */
    intnum = 456;
    res = bzp.getPrimeFactors(intnum).toString();
    alert(res);
    // Result is: 2,2,2,3,19

/* Calculating the smallest common multiple
    */
    intnum1 = 12;
    intnum2 = 15;
    res = bzp.getSmlComMultiple(intnum1, intnum2);
    alert(res);
    // Result is: 60

/* Calculating the greatest common divisor
    */
    intnum1 = 12;
    intnum2 = 48;
    res = bzp.getGrtComDivisor(intnum1, intnum2);
    alert(res);
    // Result is: 12

/* Calculates the simplify fraction
    */
    fraction = "12/48";
    res = bzp.getSimpFract(fraction);
    alert(res);
    // Result is: "1/4"

/* Calculatin the next prime number
    */
    res = "The last prime was: "+bzp.aprime[bzp.aprime.length-1]+", the next prime is: "+bzp.getNext();
    alert(res);
    // Result is: The last prime was: 3571, the next prime is: 3581

    //get next 10 prime numbers
    for(i=0;i<10;i++) bzp.getNext();
    res = "The new count of prime number is: "+bzp.aprime.length;
    alert(res);
    // Result is: The new count of prime number is: 511

/* Error handling
    If the prime numbers registered in the object are not enough to solve the operation the onNotEnoughPrime event is calling:
    */
    bzp.onNotEnoughPrime = function() { alert("The prime numbers are not enougth to solve this probelm. Use the getNext methode to calculate more numbers.") }
    bzp.getPrimeFactors(12823561);