Math hepl needed

Hello,

I'm trying to do calculate Local Sidereal Time with precision for a project
for the function below the arguments are
DDMMYY is the date as an integer
Time is calculated with formula (SS/3600 + MM/60 + HH)*1000000

long LMST(int DDMMYY, long Time)
{
  byte YY = DDMMYY % 100;
  byte MM = (DDMMYY % 10000) / 100;
  byte DD = DDMMYY / 100;
  if(MM < 2)//YY & MM correction
  {
    MM +=12;
    YY -=1;
  }
  //Julian Day =INT(365,25*(YEAR+4716))+INT(30,6001*(MONTH+1))+Day-13-1524,5+UTC_As_Long
  //MJD = Julian Day - 2400000.5
  uint64_t MJD = (365250000 * (YY + 6716)) + (30600100 * (MM+1)) - 2400000500000;
  //MJD0 = integer part of MJD
  unsigned long MJD0 = MJD / 1000000L;
  //UT = (MJD - MJD0)*24
  unsigned long UT = (MJD - MJD0) * 24;
  //T_EPH  = (MJD0-51544.5)/36525.0
  unsigned long T_EPH = (MJD0 - 5144500000)/36525000000;
  //GMST = 6,697374558+1,0027379093*ut+(8640184,812866+(0,093104-0,0000062*t_eph)*t_eph)*t_eph/3600
  uint64_t GMST = 6697374 + 1002737 * UT + (8640184812866 + (93104 - 6 * T_EPH) * T_EPH) * T_EPH/3600;
  //Frac=(GMST + longitude/15.0)/24.0
  unsigned long Frac = (GMST + Lng/15)/24;
  //LMST=24*Frac
  return 24 * Frac;
}

When i try to compile i get the error " error: integer constant is too large for 'long' type"
at uint64_t MJD = ...

Any advice on how to solve the proble and maybe how to improve the function?

Thank you

When i try to compile i get the error " error: integer constant is too large for 'long' type"

I think you will have to use floating point numbers. This of course reduces the accuracy but short of implementing a long long arithmetic package is all I can think of.

your 64-bit number literals are being compiled as longs

rename them with a 'LL' suffix for long long

uint64_t MJD = (365250000 * (YY + 6716)) + (30600100 * (MM+1)) - 2400000500000LL;

This:
byte DD = DDMMYY / 100;
should be this:
byte DD = DDMMYY / 10000;

Otherwise DD will be DDMM.

Pete

Thanks PYRO, LL did the job, i had no idea that i have to use LL.

The function is a draft (as you can see i didn't include all the parameters) bu if you have any suggestions on how to improve it
it will be great.

Thank you.

In C the meaning of "long" depends on the compiler/architecture - many systems use int = 32bit, long = 64bit, but on a microcontroller it makes a lot more sense for int = 16bit, long=32bit, long long=64bit.