Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Nan Annoying problem

    Good morning,

    I have a few simple JS routines in a php file which work - at least most of it.

    One of the called routines is something like this:

    Code:
    function ephemeris_m_2(date,longitude,latitude,h_sys){
    $const.tlong = longitude;
    $const.glat = latitude;
    $processor.init ();
    var LongitudeG1 = new Array();
    for(i=0;i<11;i++){
    var body = $moshier.body[nbody[i]];
    $processor.calc (date, body);
    LongitudeG1[i+1] = fixto360($const.body.position.apparentLongitude);
    }
    var nodesG1 = new Array();
    nodesG1 = bi(date.julian);
    var houses_G1 = new Array();
    houses_G1 = bF(date.julian,longitude,latitude,h_sys);
    (etc...)
    All the returned results are correct except the var houses_G1, which returns an array of Nan,Nan,Nan...etc.

    BUT if I place, for example,

    Code:
    houses_G1 = bF(date.julian,-8,43.2,h_sys);
    I get the correct results. So, for some reason the vars longitude and latitude are not being received correctly. But they are in the previous routines! And they are not changed: a simple alert(longitude) before calling the bF routine returns the correct value...

    Any ideas? I even tryed placing 2 new vars l1 and l2 equal to longitude and latitude at the beginning of the code and use them in bF - no luck... I think it's a scope issue.

    Kind regards,

    Kepler

  2. #2
    New Coder
    Join Date
    Mar 2011
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi,

    Problem solved. Both variables longitude and latitude were not being interpreted as numbers. So I created a var longitude1=eval(longitude) and var latitude1 = eval(latitude) and it worked

  3. #3
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,764
    Thanks
    26
    Thanked 596 Times in 589 Posts
    never use eval()!!! if they are numbers, use Number().
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  4. Users who have thanked Dormilich for this post:

    kepler (Jun 11th, 2018)

  5. #4
    New Coder
    Join Date
    Mar 2011
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Ooops... You are right Thanks.


 

Tags for this Thread

Posting Permissions

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