Results 1 to 2 of 2

Thread: problems with beeeeeg numbers

  1. #1
    Join Date
    Feb 2005
    Posts
    6

    problems with beeeeeg numbers

    Hi folks - I'm a bit of a novato with JS and have written some science calculations programs using Avogador's number 6.02e23.
    The problem is that when I set a variable to this number and then perform calculations with it it returns the "invalid floating point" error warning (and the computer crashes!)
    However, this doesn't happen on the HTML version of the pages - only on the e-book that I am compiling using the html (I am using ebook edit pro)

    The calculations I am using are fairly simple, as follows:

    //initialise variables------------
    attempts=0
    total=0
    correct=0
    tried=0
    avo=6.02E23
    ans=""
    RMMs=new Array(18,44,28,80,32,28,17,256,58.5,167,188,40,56,208,62)

    function begin(){
    n=Math.round(14*Math.random())
    RMM=RMMs[n]
    mass=Math.round(4*Math.pow(10,Math.random()))/100
    Vg=Math.round(4*Math.pow(10,Math.random()))/100
    moles=mass/RMM
    display()
    }

    function display(){
    dimV=" cm<sup>3</sup>"
    dimM=" g"
    dimV2=" dm<sup>3</sup>"

    var h=Math.round(2.5*Math.random())
    if(n<8){
    h=0
    }
    if(n>7){
    h=2
    }

    if(h==0){
    v1=Vg+dimV
    v2=mass+dimM
    ans=moles*avo
    }
    if(h==1){
    v1=Vg+dimV
    v2=mass+dimM
    ans=moles*avo
    }
    if(h==2 & n>7 & n<13){
    v1=Vg+dimV
    v2=mass+dimM
    ans=moles*avo
    ans=2*ans
    }
    if(h==2 & n>12){
    v1=Vg+dimV
    v2=mass+dimM
    ans=moles*avo
    ans=3*ans
    }
    ans=ans.toPrecision(3)
    setthequestion()
    }

    and then I have to functions to set the question and show the answers. If I set the variable 'avo' to simple numbers the script has no problems but as it is a very large number 6.02 x 10(23) this causes the system to register the error.

    My question is simple - is there a work around for this problem?

    Any help would be greatly appreciated

    Thanks

  2. #2
    Join Date
    Mar 2004
    Location
    China
    Posts
    3,315
    The first step is to find which of your lines of code causes the error. Without knowing where in the code you get the error, we have to just guess. Try echoing the result to the screen are various points in the code to see just where the bug is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •