Skip to main content

deep_time/
constants.rs

1//! Fundamental constants for time-scale conversions,
2//! relativistic corrections, and astronomical calculations.
3
4use crate::{Dt, Real, Scale};
5
6/// The size limit for parsing and no-alloc formatting with
7/// the strtime related functionality.
8pub const STRTIME_SIZE: usize = 512;
9
10pub(crate) const ATTOS_DIGITS: usize = 18;
11pub(crate) const SEC_PER_YEAR: i128 = 31_557_600; // 365.25 days × 86_400
12pub(crate) const SEC_PER_MONTH: i128 = 2_629_800; // 30.4375 days × 86_400
13pub(crate) const SEC_PER_DAY: i128 = 86_400;
14
15/// 86,400 seconds in one standard Earth day  
16/// (24 hours × 60 minutes × 60 seconds).
17pub const SEC_PER_DAY_F: Real = 86_400.0;
18
19/// 86,400 seconds in one standard Earth day  
20/// (24 hours × 60 minutes × 60 seconds).
21pub const SEC_PER_DAYI64: i64 = 86_400;
22pub(crate) const SEC_PER_DAYI128: i128 = 86_400;
23
24/// Seconds in one GPS week (7 days).
25pub(crate) const SEC_PER_WEEK: i64 = 7 * SEC_PER_DAYI64;
26/// Attoseconds in one GPS week.
27pub(crate) const ATTOS_PER_WEEK: i128 = SEC_PER_WEEK as i128 * ATTOS_PER_SEC_I128;
28pub const ATTOS_PER_DAY: i128 = SEC_PER_DAYI128 * ATTOS_PER_SEC_I128;
29pub const ATTOS_PER_HALF_DAY: i128 = ATTOS_PER_DAY / 2;
30pub const ATTOS_PER_HALF_DAYU: u128 = ATTOS_PER_HALF_DAY as u128;
31
32/// Attoseconds per second.
33pub const ATTOS_PER_SEC: u64 = 1_000_000_000_000_000_000;
34pub const ATTOS_PER_SECF: Real = f!(1_000_000_000_000_000_000.0);
35pub const ATTOS_PER_SEC_I128: i128 = ATTOS_PER_SEC as i128;
36pub const ATTOS_PER_SEC_U128: u128 = ATTOS_PER_SEC as u128;
37
38/// Attoseconds per millisecond (10⁻³ s).
39pub const ATTOS_PER_MS: u64 = 1_000_000_000_000_000;
40/// Attoseconds per microsecond (10⁻⁶ s).
41pub const ATTOS_PER_US: u64 = 1_000_000_000_000;
42/// Attoseconds per nanosecond (10⁻⁹ s).
43pub const ATTOS_PER_NS: u64 = 1_000_000_000;
44/// Attoseconds per picosecond (10⁻¹² s).
45pub const ATTOS_PER_PS: u64 = 1_000_000;
46/// Attoseconds per femtosecond (10⁻¹⁵ s).
47pub const ATTOS_PER_FS: u64 = 1_000;
48/// Attoseconds per millisecond (10⁻³ s).
49pub const ATTOS_PER_MS_I128: i128 = ATTOS_PER_MS as i128;
50/// Attoseconds per microsecond (10⁻⁶ s).
51pub const ATTOS_PER_US_I128: i128 = ATTOS_PER_US as i128;
52/// Attoseconds per nanosecond (10⁻⁹ s).
53pub const ATTOS_PER_NS_I128: i128 = ATTOS_PER_NS as i128;
54/// Attoseconds per picosecond (10⁻¹² s).
55pub const ATTOS_PER_PS_I128: i128 = ATTOS_PER_PS as i128;
56/// Attoseconds per femtosecond (10⁻¹⁵ s).
57pub const ATTOS_PER_FS_I128: i128 = ATTOS_PER_FS as i128;
58
59/// 0.184 sec as u64 attoseconds
60pub(crate) const TT_TAI_OFFSET_SUBSEC: u64 = 184_000_000_000_000_000; // 0.184 × 10¹⁸
61
62/// Helper that returns the TT–TAI offset as a `Dt` 32.184 s
63pub const TT_TAI_OFFSET: Dt = Dt::new(32_184_000_000_000_000_000i128, Scale::TAI, Scale::TAI);
64
65/// Julian Date of the J2000.0 epoch.
66pub const JD_2000_2_451_545: i64 = 2_451_545;
67pub const JD_2000_2_451_545F: Real = f!(2_451_545.0);
68/// MJD 40587.0 = 1970-01-01 00:00:00 UTC
69pub const MJD_1970: i64 = 40_587;
70/// Number of TAI seconds backwards from noon 2000-01-01 to midnight 1972-01-01
71pub const TAI_ATTOS_AT_1972: i128 = -883_655_990_000_000_000_000_000_000;
72
73/// TAI secs from 1970-01-01 midnight to 2000-01-01 noon
74pub(crate) const TAI_SECS_1970_MIDNIGHT_TO_2000_NOON: i64 = 946_728_000;
75
76/// L_G = 6.969290134 × 10^{-10} (IAU) as fixed-point fraction.
77pub(crate) const LG_NUM: i128 = 6_969_290_134;
78pub(crate) const LG_DEN: i128 = 10_000_000_000_000_000_000; // 10^19
79
80/// L_B = 1.550519768 × 10^{-8} (IAU) as fixed-point fraction.
81pub(crate) const LB_NUM: i128 = 1_550_519_768;
82pub(crate) const LB_DEN: i128 = 100_000_000_000_000_000; // 10^17
83
84/// TCG/TCB reference epoch (JD 2443144.5003725) broken into integer parts for exact math.
85pub(crate) const TCG_TCB_REF_JD_INT: i64 = 2_443_144;
86pub(crate) const TCG_TCB_REF_TOD_SEC: i64 = 43_232; // 0.5003725 * 86400 = 43232.184
87pub(crate) const TCG_TCB_REF_TOD_SUBSEC: u64 = TT_TAI_OFFSET_SUBSEC;
88
89/// Attoseconds since J2000.0 TT of the TCG/TCB reference epoch
90/// (JD 2443144.5003725 TT). Computed from the existing reference constants.
91pub(crate) const TCG_TCB_REF_ATTOS_SINCE_J2000: i128 = {
92    let days_since_j2000 = (TCG_TCB_REF_JD_INT - JD_2000_2_451_545) as i128;
93    let sec_part = days_since_j2000 * SEC_PER_DAYI128 + (TCG_TCB_REF_TOD_SEC as i128);
94    sec_part * ATTOS_PER_SEC_I128 + (TCG_TCB_REF_TOD_SUBSEC as i128)
95};
96
97/// TDB₀ = −65.5 µs expressed in attoseconds.
98pub(crate) const TDB0_ATTOS: i128 = -65_500_000_000_000;
99
100/// Solar gravitational parameter GM☉ in m³ s⁻²  
101/// (nominal value from IAU 2015 Resolution B3)
102#[cfg(feature = "physics")]
103pub const GM_SUN: Real = 1.3271244e20;
104
105/// Speed of light in m/s (SI definition)
106#[cfg(feature = "physics")]
107pub const C: Real = 299792458.0;
108
109/// Speed of light squared (c²) in m² s⁻².  
110#[cfg(feature = "physics")]
111pub const C_SQUARED: Real = C * C;
112
113/// GM☉ / c³ in seconds (from `GM_SUN` and `C` — used in Shapiro delay)
114#[cfg(feature = "physics")]
115pub const GM_SUN_OVER_C3: Real = GM_SUN / (C * C_SQUARED);
116
117/// 2GM☉ / c³ — the standard prefactor in the one-way Shapiro delay formula
118#[cfg(feature = "physics")]
119pub const TWO_GM_SUN_OVER_C3: Real = 2.0 * GM_SUN_OVER_C3;
120
121/// Planck length ℓ_Pl in meters (standard value).
122///
123/// This is raised to the fourth power to form the dimensionless curvature
124/// parameter `x = ℓ_Pl⁴ × 𝒦` inside the master Lagrangian. The term only
125/// affects the proper-time rate at extreme (Planckian) curvatures.
126/// See the [relativistic timing model](https://github.com/ragardner/deep-time/blob/main/docs/relativity.md).
127#[cfg(feature = "physics")]
128pub const PLANCK_LENGTH: Real = 1.616255e-35;
129
130/// Planck length to the fourth power (ℓ_Pl⁴) in m⁴.
131///
132/// This is the coefficient actually used at runtime:
133///
134/// ```text
135/// let x = PLANCK_LENGTH_4 * kretschmann;
136/// ```
137///
138/// The fourth power produces a dimensionless `x` because the Kretschmann
139/// scalar has units of L⁻⁴. Information on the underlying model can be found
140/// [here](https://github.com/ragardner/deep-time/blob/main/docs/relativity.md).
141#[cfg(feature = "physics")]
142pub const PLANCK_LENGTH_4: Real = PLANCK_LENGTH * PLANCK_LENGTH * PLANCK_LENGTH * PLANCK_LENGTH;