1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
use crate;
/// `MAXA(value1, ...)` — largest value, coercing booleans (TRUE=1, FALSE=0).
/// - Numbers included directly.
/// - Booleans coerced: TRUE=1, FALSE=0.
/// - Text in direct args → `#VALUE!`.
/// - Empty → skip.
/// - Empty array argument → `#REF!`.
/// - Array of nothing but blanks → 0.
/// - No args → `#N/A`.
///
/// **Dates participate as bare serials** and carry their type out, exactly as
/// they do for MAX: a date-only range answers the latest date, a date beside a
/// plain number is compared on the serial, and the result is date-typed
/// whenever a date took part — even when a plain number won.
///
/// Captured alongside the MAX/MIN forms, which agree with MAXA on every date
/// input — but captured and extrapolated are not the same thing here:
///
/// - **Values** are captured in Google Sheets for every form — a date-only
/// column, a date/number column, array literals of both shapes, and dates
/// passed as direct arguments.
/// - **Typing** is captured for the *range* forms only, read back through the
/// cell that holds the result. The literal and direct-argument rows report
/// `number`, but that is an artifact of the capture harness reading them
/// through an `INDEX(...,1,1)` wrapper, which drops the cell's date format —
/// it is not a Sheets answer. So the date typing of
/// `=MAXA({DATE(...),DATE(...)})` is **extrapolated** from the range forms,
/// not probed.
///
/// **None of those rows are in this repo yet.** They come off the
/// conformance-fixtures pipeline and land in a separate fixtures-only PR —
/// they fail until this code exists, and CI rejects a PR that mixes fixture
/// TSVs with code. Same arrangement as the blank-only rows described on
/// `stat_helpers::is_blank_only_array`. A reviewer working from this repo
/// alone can check the unit tests and this comment; the Sheets answers
/// themselves have to be taken from that pipeline.
///
/// # Zone-aware values (#781)
///
/// MAXA consults [`stat_helpers::zoned_extreme`] before its argument loop,
/// exactly as MAX does: zoned instants on their own answer the latest,
/// preserving its zone; a zoned instant mixed with anything that contributes a
/// number — `Number`, `Date`, `Bool` or `Text` — is `#VALUE!`.
///
/// This is a **deliberate truecalc-only decision, not a captured Sheets
/// answer.** `Zoned` is a truecalc extension with no Sheets equivalent, so the
/// conformance oracle cannot settle it. Two answers were defensible — error
/// like the siblings, or teach all four to compare a zoned instant against a
/// naive serial — and the first was chosen because:
///
/// - MAX and MIN already answer `#VALUE!` here, and `MAXA(<zoned>, <date>)`
/// answering a confident date while `MAX` of the same arguments errors is a
/// difference no caller can predict from the function name;
/// - the alternative requires inventing a naive-vs-aware comparison rule with
/// no ground truth behind it, which is strictly more invention;
/// - the collectors that were checked already refuse a zoned instant —
/// `collect_nums_direct`, `collect_nums_a_direct` and `collect_nums_a_checked`
/// all return `#VALUE!` — so erroring is not a new rule for this family.
/// That is three collectors, not all of them: several others still skip a
/// `Zoned` silently, and squaring them up is out of scope here;
/// - the behaviour it replaces was the failure mode both #780 and #781 are
/// about — a zone-aware value silently dropped, leaving a plausible-looking
/// number in place of a visible error.
///
/// The check runs **before** the argument loop, so it precedes the empty-array
/// `#REF!`, the sparkline-only 0 and the blank-only 0. A `Zoned` mixed with any
/// of those three therefore answers by the zoned rule rather than by theirs —
/// which is exactly the ordering MAX and MIN have always had, and the point of
/// this change is that the four agree.
///
/// [`stat_helpers::zoned_extreme`]: super::stat_helpers::zoned_extreme
///
/// This costs a second recursive pass over the arguments on the common
/// no-zoned path, where it always returns `None`. Accepted deliberately: MAX
/// and MIN already pay it, and paying it is what makes the four answer alike.
/// Recurse into nested arrays (e.g. a vertical range materializes as nested
/// one-element row arrays) so every cell is visited, folding into `result`
/// with MAXA's array-context coercion rules.
/// A sparkline is skipped wherever it appears, and an aggregate whose scope
/// holds nothing else answers 0 — the same answer whether it arrived as a
/// direct argument or through a range (google.tsv: `=MAXA(SPARKLINE({1,2,3}))`
/// and `=MAXA(Data!K1:K1)` are both 0). The flag is what distinguishes "skipped a
/// sparkline" from "saw nothing usable at all", which stay different answers.