TCB top-level property
Barycentric Coordinate Time (TCB): TCB = TDB + (1.550505e-8)(JD - 2443144.5)(86400)
Implementation
// ignore: non_constant_identifier_names
final TimeInstantUnits TCB = TimeInstantUnits(
'Barycentric Coordinate Time', null, 'TCB', null, 1.0 - 1.550505e-8, false, 599616000.0 - 32.184, (dynamic val) {
final d = val is num
? val.toDouble()
: val is Number
? val.toDouble()
: 0.0;
var tdb = TDB.fromMks(val); // TDB seconds
return tdb += 1.550505e-8 * (d - 5.99616e8);
}, (dynamic val) {
final d = val is num
? val.toDouble()
: val is Number
? val.toDouble()
: 0.0;
// Too convoluted to solve analytically... instead, get close and then search
var taiTest = d;
var step = 10.0;
const epsilon = 1.0e-8;
const maxCount = 10000;
var count = 0;
var tcbTest = TCB.fromMks(d).toDouble();
var delta = tcbTest - taiTest;
var prevDelta = double.maxFinite;
while ((delta.abs() > epsilon) && (count < maxCount)) {
// See if we got farther away (if so reverse and take smaller steps)
if (delta.abs() > prevDelta.abs()) step *= -0.5;
// Step
taiTest += step;
prevDelta = delta;
count++;
// value & delta
tcbTest = TCB.fromMks(taiTest).toDouble();
delta = tcbTest - d;
}
// taiTest now returns a tcb value within epsilon (or loop count ran out)
return Double(taiTest);
});