Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6641267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:47:26+00:00 2026-05-25T23:47:26+00:00

I am converting a some C++ to java and have a small bit that

  • 0

I am converting a some C++ to java and have a small bit that I am unsure about
first question is what is tested for in the line

if (ampconst[i][0] || ampconst[i][1])

this in an example to the data in the array.

 static short ampconst[NUT_SERIES][2] = {
{0,0},
{0,0},
{46,-24}
};

and my second question is that the ampsecul array is far shorter than NUT_SERIES
so I am getting array out of bounds exceptions, the array terminates like so

static long ampsecul[][5] = {
{0  ,-171996 ,-1742 ,92025 ,89},
{1  ,2062    ,2     ,-895  ,5},
{8  ,-13187  ,-16   ,5736  ,-31},
{9  ,1426    ,-34   ,54    ,-1},
{10 ,-517    ,12    ,224   ,-6},
{11 ,217     ,-5    ,-95   ,3},
{12 ,129     ,1     ,-70   ,0},
{15 ,17      ,-1    ,0     ,0},
{17 ,-16     ,1     ,7     ,0},
{30 ,-2274   ,-2    ,977   ,-5},
{31 ,712     ,1     ,-7    ,0},
{32 ,-386    ,-4    ,200   ,0},
{33 ,-301    ,0     ,129   ,-1},
{37 ,63      ,1     ,-33   ,0},
{38 ,-58     ,-1    ,32    ,0},
/* termination */  { -1, }
};

so how could this be handled in java and what would the values be at these lines
when the array is out of bounds or how would C++ handle this.

ampsin = ampsecul[isecul][1] + ampsecul[isecul][2] * T10;
ampcos = ampsecul[isecul][3] + ampsecul[isecul][4] * T10;

thanks in advance for any advice.
This is the whole for loop too see the code in context.

for (i = isecul = 0; i < NUT_SERIES ; ++i) {
    double arg = 0., ampsin, ampcos;
    short j;

    if (ampconst[i][0] || ampconst[i][1]) {
    /* take non-secular terms from simple array */
    ampsin = ampconst[i][0];
    ampcos = ampconst[i][1];
    } else {
    /* secular terms from different array */
    ampsin = ampsecul[isecul][1] + ampsecul[isecul][2] * T10;
    ampcos = ampsecul[isecul][3] + ampsecul[isecul][4] * T10;
    ++isecul;
    }

    for (j = 0; j < 5; ++j)
    arg += delcache[j][NUT_MAXMUL + multarg[i][j]];

    if (fabs(ampsin) >= prec)
    lastdpsi += ampsin * sin(arg);

    if (fabs(ampcos) >= prec)
    lastdeps += ampcos * cos(arg);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:47:27+00:00Added an answer on May 25, 2026 at 11:47 pm
      if (ampconst[i][0] || ampconst[i][1])
    

    tests whether the first/second column in ampconst[i] contain non-zero (it is an early-out optimization: if both the constants are 0 then the calculation can be skipped)

    Edit I just found (google!) that this is a nutation calculation that has been adopted in quite a few places, but seems to be originally from a libastro.

         hg clone https://bitbucket.org/brandon/pyephem
    

    As far as the isecul index is concerned: apparently isecul should never grow to >= 15 (note that i is the loop variable, not isecul, isecul is incremented conditionally).

    However, seeing the ‘terminator’ (-1) value, I’d really expect a check some like

    if (ampsecul[isecul][0] == -1)
       isecul = 0; // ? just guessing :)
    

    or

    if (ampsecul[isecul][0] == -1)
       break;
    

    Also, I get the impression that the first column of ampsecul is a range-based division, so somehow, there would be a binarysearch for the matching slot into ampsecul, not direct indexing (i.e. isecul=4 would select index 2 (2..8) not 4)

    Are you sure you are getting the source code correctly? I looks very much like there are some custom indexers (operators[](...)) that you misssed out on? This would probably be about the same class/function that contains the terminator check like shown above.
    Edit from the linked source I get the impression that the code is very much intended as is, and hence isecul should simply not be growing >= 15

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that I'm converting from Perl to Java. It makes pretty
I'm converting some old Java code to Scala. I have this. class XYCustomRenderer(dataMax: Double,
I am converting some Java code to C#. This code is using getGlyphOutline from
I am maintaining some Java code that I am currently converting to C#. The
I have some strings in Java (originally from an Excel sheet) that I presume
I am converting some Java code to C# and have found a few labelled
Say I have a very simple java object that only has some getXXX and
I have some old 3rd party Java code I am converting to Java 6.
I'm converting some services from Apache SOAP to Axis2, so the Java service classes
I am manually converting code from Java (1.6) to C# and finding some difficulty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.