Branch: Tag:

2014-12-03

2014-12-03 14:48:23 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Calendar: Fixed deltat calculation and tables.

Also adds some tests.

59:   // @elem float 2   // Year divisor.   // @elem float 3.. - // Polynomial factors with the highest exponent first. + // Polynomial factors with the highest exponent last.   // @endarray   protected constant deltat_polynomials = ({    ({ -500.0, -1820.0, 100.0,    -20.0, 0.0, 32.0, }),    ({ 500.0, 0.0, 100.0, -  0.0090316521, 0.022174192, -0.1798452, -  -5.952053, 33.78311, -1014.41, 10583.6, }), +  10583.6, -1014.41, 33.78311, -5.952053, +  -0.1798452, 0.022174192, 0.0090316521, }),    ({ 1600.0, -1000.0, 100.0, -  0.0083572073, -0.005050998, -0.8503463, -  0.319781, 71.23472, -556.01, 1574.2, }), +  1574.2, -556.01, 71.23472, 0.319781, +  -0.8503463, -0.005050998, 0.0083572073, }),    ({ 1700.0, -1600.0, 1.0, -  0.000140272128, -0.01532, -0.9808, 120.0, }), +  120.0, -0.9808, -0.01532, 0.000140272128, }),    ({ 1800.0, -1700.0, 1.0, -  0.000000851788756, 0.00013336, -0.0059285, 0.1603, 8.83, }), +  8.83, 0.1603, -0.0059285, 0.00013336, -0.000000851788756, }),    ({ 1860.0, -1800.0, 1.0, -  0.000000000875, -0.0000001699, 0.0000121272, -0.00037436, -  0.0041116, 0.0068612, -0.332447, 13.72, }), +  13.72, -0.332447, 0.0068612, 0.0041116, -0.00037436, +  0.0000121272, -0.0000001699, 0.000000000875, }),    ({ 1900.0, -1860.0, 1.0, -  0.000004288643, -0.0004473624, 0.01680668, -0.251754, 0.5737, 7.62, }), +  7.62, 0.5737, -0.251754, 0.01680668, -0.0004473624, 0.000004288643, }),    ({ 1920.0, -1900.0, 1.0, -  -0.000197, 0.0061966, -0.0598939, 1.494119, -2.79, }), +  -2.79, 1.494119, -0.0598939, 0.0061966, -0.000197, }),    ({ 1941.0, -1920.0, 1.0, -  0.0020936, -0.076100, 0.84493, 21.20, }), +  21.20, 0.84493, -0.076100, 0.0020936, }),    ({ 1961.0, -1950.0, 1.0, -  0.0003926188, 0.0042918455, 0.407, 29.07, }), +  29.07, 0.407, -0.0042918455, 0.0003926188, }),    ({ 1986.0, -1975.0, 1.0, -  0.001392758, 0.0038461538, 1.067, 45.45, }), +  45.45, 1.067, -0.0038461538, -0.001392758, }),    ({ 2005.0, -2000.0, 1.0, -  0.00002373599, 0.000651814, 0.0017275, -0.060374, 0.3345, 63.86, }), +  63.86, 0.3345, -0.060374, 0.0017275, 0.000651814, 0.00002373599, }),    ({ 2050.0, -2000.0, 1.0, -  0.005589, 0.32217, 62.92 }), +  62.92, 0.32217, 0.005589, }),    ({ 2150.0, -1820.0, 100.0, -  32.0-185.724, 56.28, -20.0, }), +  -20.0-185.724, 56.28, 32.0, }),    ({ Math.inf, -1820.0, 100.0, -  32.0, 0.0, -20.0, }), +  -20.0, 0.0, 32.0, }),   });      //! method float deltat(int unadjusted_utc)
126:    if (y < polynomial[0]) h = c;    else l = c + 1;    } while (l < h); +  polynomial = deltat_polynomials[l]; +     float u = (y + polynomial[1])/polynomial[2];       float deltat = 0.0; -  +  float p = 1.0;    foreach(polynomial; int i; float factor) {    if (i < 3) continue; -  deltat = deltat * u + factor; +  deltat += factor * p; +  p = p * u;    }    return deltat;   }