The sun's altitude and azimuth for a date, clock time, latitude, longitude and time zone, and the direction shadows are cast from.
How the precision is kept
The arithmetic is 64-bit, but the accuracy is that of the formulas: the short Fourier series for the equation of time and the declination that the file header cites from the NOAA Global Monitoring Laboratory's General Solar Position Calculations. The header states the result is good to a fraction of a degree and that refraction is ignored.
Calculations under this policy
5 calculations in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.
N = days before the month + day (+1 after February in a leap year)
Whole-number arithmetic with the Gregorian leap rule (divisible by 4, not by 100 unless by 400).
m3d/sun.js
lines 17 to 21
CadCraft 0.8.2
export function dayOfYear(month, day, year = 2026) {
const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
const cum = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
return cum[month - 1] + day + (leap && month > 2 ? 1 : 0);
}
Equation of time and declination
64-bit
How far sun time runs ahead of clock time, and the sun's angle above the equator, for the date.
γ = 2π ÷ (365 or 366) × (N − 1 + (hour − 12) ÷ 24); eqtime = 229.18 × (0.000075 + 0.001868 cos γ − 0.032077 sin γ − 0.014615 cos 2γ − 0.040849 sin 2γ)
Two short trigonometric series with coefficients given to 6 decimals; 229.18 turns radians into minutes. The series, not the arithmetic, set the accuracy.
tst = hour × 60 + eqtime + 4 × lon − 60 × tz; H = tst ÷ 4 − 180°; cos Z = sin φ sin δ + cos φ cos δ cos H; altitude = 90° − Z
cos Z is clamped to [−1, 1] before acos. When the sun is almost overhead cos Z is close to 1, where acos turns a small error in its input into a larger one in the angle.
Fractional year γ; equation of time and declination from Spencer's Fourier series (as cited in the file header); true solar time from longitude and time zone; zenith from the spherical cosine formula; azimuth from atan2.
Number types
64-bit numbers; angles in radians inside, degrees in the result.
Tolerances
cos of the zenith angle is clamped to [−1, 1] before acos.
Limits
Series coefficients are the published rounded decimals. No atmospheric refraction. The year only decides 365 or 366 days.
Approach: 64-bit, stated limit
The arithmetic is 64-bit, but the method or the data sets the accuracy: a solver tolerance, a mesh, a step size, a datum shift, a table. The limit is stated where the result is shown.