xref: /trunk/audit/openformula-function-gaps/biff-function-mapping-audit.md (revision 195598447694ec8542914a9b51ae9942e8ebacd9)
14f909564SJim Jagielski<!--
24f909564SJim Jagielski Licensed to the Apache Software Foundation (ASF) under one
34f909564SJim Jagielski or more contributor license agreements.  See the NOTICE file
44f909564SJim Jagielski distributed with this work for additional information
54f909564SJim Jagielski regarding copyright ownership.  The ASF licenses this file
64f909564SJim Jagielski to you under the Apache License, Version 2.0 (the
74f909564SJim Jagielski "License"); you may not use this file except in compliance
84f909564SJim Jagielski with the License.  You may obtain a copy of the License at
94f909564SJim Jagielski
104f909564SJim Jagielski   http://www.apache.org/licenses/LICENSE-2.0
114f909564SJim Jagielski
124f909564SJim Jagielski Unless required by applicable law or agreed to in writing,
134f909564SJim Jagielski software distributed under the License is distributed on an
144f909564SJim Jagielski "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
154f909564SJim Jagielski KIND, either express or implied.  See the License for the
164f909564SJim Jagielski specific language governing permissions and limitations
174f909564SJim Jagielski under the License.
184f909564SJim Jagielski-->
194f909564SJim Jagielski
2047032aefSPedro GiffuniBIFF Formula Function Mapping Audit
2147032aefSPedro Giffuni====================================
2247032aefSPedro Giffuni
2347032aefSPedro GiffuniBranch: openformula
2447032aefSPedro GiffuniHEAD: a330cbd51b (DATEDIF BIFF import mapping fix)
2547032aefSPedro GiffuniAudit type: Read-only source inspection (no build, no runtime execution)
2647032aefSPedro Giffuni
274f909564SJim JagielskiUpdated 2026-11-18 to match the code after the post-merge review. Rows marked
284f909564SJim Jagielski"run" were written to xls by AOO, read back by AOO and opened in Excel 16.
294f909564SJim Jagielski
3047032aefSPedro GiffuniMethodology
3147032aefSPedro Giffuni-----------
324f909564SJim Jagielski
3347032aefSPedro GiffuniInspected `main/sc/source/filter/excel/xlformula.cxx` which contains all
3447032aefSPedro GiffuniBIFF formula function mapping tables:
3547032aefSPedro Giffuni
3647032aefSPedro Giffuni- saFuncTable_2 (BIFF2, IDs 0-211)
3747032aefSPedro Giffuni- saFuncTable_3 (BIFF3, IDs 219-244)
3847032aefSPedro Giffuni- saFuncTable_4 (BIFF4, IDs 214-332)
3947032aefSPedro Giffuni- saFuncTable_5 (BIFF5/7, IDs 70-354)
4047032aefSPedro Giffuni- saFuncTable_8 (BIFF8, IDs 358-367)
414f909564SJim Jagielski- saFuncTable_Oox (OOXML future functions, `_xlfn.` prefix, NOID/255)
424f909564SJim Jagielski- saFuncTable_Odf (OpenFormula namespace, `_xlfnodf.` prefix, NOID/255)
4347032aefSPedro Giffuni
4447032aefSPedro GiffuniImport path: `FillXclFuncMap()` skips EXC_FUNCFLAG_EXPORTONLY entries,
4547032aefSPedro Giffuniadds entries with non-NOID BIFF function IDs to maXclFuncMap.
4647032aefSPedro GiffuniExport path: `FillScFuncMap()` skips EXC_FUNCFLAG_IMPORTONLY entries,
4747032aefSPedro Giffuniadds all others to maScFuncMap keyed by opcode.
4847032aefSPedro Giffuni
4947032aefSPedro GiffuniBIFF function IDs and Calc opcode IDs are distinct namespaces. A BIFF
5047032aefSPedro Giffunifunction ID is the number Excel uses in its binary file format; a Calc
5147032aefSPedro Giffuniopcode is AOO's internal representation. The BIFF tables map between them.
5247032aefSPedro Giffuni
5347032aefSPedro GiffuniInventory
5447032aefSPedro Giffuni---------
5547032aefSPedro Giffuni
564f909564SJim Jagielski32 rows. The functions of the OpenFormula compatibility work (H.1-H.9), the
574f909564SJim Jagielskiother function-gap entries and the B-function family (LENB/RIGHTB/MIDB/LEFTB).
5847032aefSPedro Giffuni
5947032aefSPedro Giffuni| # | Function | Opcode | Native Evaluator | BIFF ID | Import | Export | Classification |
6047032aefSPedro Giffuni|---|----------|--------|-----------------|---------|--------|--------|----------------|
614f909564SJim Jagielski| 1 | NUMBERVALUE | ocNumberValue (392) | Yes | None (_xlfnodf) | NOID import-only | 255 export-only | Correct; Excel shows #NAME? (run) |
624f909564SJim Jagielski| 2 | FINDB | ocFindB (412) | Yes | BIFF2 ID 205 | both | both | Correct (added 2026-11-18; run) |
634f909564SJim Jagielski| 3 | SEARCHB | ocSearchB (413) | Yes | BIFF2 ID 206 | both | both | Correct (added 2026-11-18) |
644f909564SJim Jagielski| 4 | REPLACEB | ocReplaceB (414) | Yes | BIFF2 ID 207 | both | both | Correct (added 2026-11-18) |
654f909564SJim Jagielski| 5 | DATEDIF | ocDateDif (415) | Yes | BIFF5 ID 351 | both | both | Correct (export added 2026-11-18; run) |
6647032aefSPedro Giffuni| 6 | IFNA | ocIfna | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct |
6747032aefSPedro Giffuni| 7 | SKEWP | ocSkewP | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct |
6847032aefSPedro Giffuni| 8 | IFERROR | ocIfError | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct |
6947032aefSPedro Giffuni| 9 | BITAND | ocBitAnd | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct |
7047032aefSPedro Giffuni| 10 | BITOR | ocBitOr | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct |
7147032aefSPedro Giffuni| 11 | BITXOR | ocBitXor | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct |
7247032aefSPedro Giffuni| 12 | BITLSHIFT | ocBitLShift | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct |
7347032aefSPedro Giffuni| 13 | BITRSHIFT | ocBitRShift | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct |
744f909564SJim Jagielski| 14 | ISOWEEKNUM | ocIsoWeekNum (416) | Yes | None (_xlfn) | NOID import-only | 255 export-only | Correct (added 2026-11-18; run) |
754f909564SJim Jagielski| 15 | WEEKNUM as ODF ISOWEEKNUM | ocWeek (365) | Yes | None (_xlfnodf) | NOID import-only | 255 export-only | Correct |
764f909564SJim Jagielski| 16 | DDE | ocDde (369) | Yes | None | none | none | Intentional limitation |
774f909564SJim Jagielski| 17 | ODDFPRICE | None (AddIn) | No | None | none | none | Intentional limitation |
784f909564SJim Jagielski| 18 | ODDFYIELD | None (AddIn) | No | None | none | none | Intentional limitation |
794f909564SJim Jagielski| 19 | RRI | ocZGZ (256) | Yes | None (_xlfnodf) | NOID import-only | 255 export-only | Correct; Excel shows #NAME? (run) |
804f909564SJim Jagielski| 20 | ERROR.TYPE | ocErrorTypeODF (419) | Yes | BIFF4 ID 261 | both | both | Correct (run) |
814f909564SJim Jagielski| 21 | ERRORTYPE | ocErrorType (151) | Yes | BIFF4 ID 261 | none | export-only | Correct; comes back as ERROR.TYPE (run) |
824f909564SJim Jagielski| 22 | GETPIVOTDATA | ocGetPivotData (390) | Yes | BIFF8 ID 358 | both | both | Correct |
834f909564SJim Jagielski| 23 | FDIST | ocFDist (315) | Yes | BIFF4 ID 281 | both | both | Correct (run) |
844f909564SJim Jagielski| 24 | FINV | ocFInv (359) | Yes | BIFF4 ID 282 | both | both | Correct (run) |
854f909564SJim Jagielski| 25 | F.DIST | ocFDistLeft (417) | Yes | None (`_xlfn.F.DIST`) | NOID import-only | 255 export-only | Correct; Excel calculates 4 arguments, #N/A for 3 (run) |
864f909564SJim Jagielski| 26 | F.INV | ocFInvLeft (418) | Yes | None (`_xlfn.F.INV`) | NOID import-only | 255 export-only | Correct; Excel calculates it (run) |
874f909564SJim Jagielski| 27 | HYPGEOMDIST | ocHypGeomDist (312) | Yes | BIFF4 ID 289 | both, 4 args | both, 4 args | Limitation: 5 args written as NA() (run) |
884f909564SJim Jagielski| 28 | HARMEAN | ocHarMean (321) | Yes | BIFF4 ID 320 | both | both | Correct |
894f909564SJim Jagielski| 29 | LEFTB | ocLeftB (402) | Yes | BIFF2 ID 208 | both | both | Correct |
904f909564SJim Jagielski| 30 | RIGHTB | ocRightB (401) | Yes | BIFF2 ID 209 | both | both | Correct |
914f909564SJim Jagielski| 31 | MIDB | ocMidB (403) | Yes | BIFF2 ID 210 | both | both | Correct |
924f909564SJim Jagielski| 32 | LENB | ocLenB (400) | Yes | BIFF2 ID 211 | both | both | Correct |
9347032aefSPedro Giffuni
9447032aefSPedro GiffuniImport Findings
9547032aefSPedro Giffuni---------------
9647032aefSPedro Giffuni
9747032aefSPedro GiffuniDATEDIF (BIFF5 ID 351): Was mapped to ocNoName → #NAME! on import. Fixed
984f909564SJim Jagielskiin commit a330cbd51b to map to ocDateDif.
9947032aefSPedro GiffuniBIFF8 table (saFuncTable_8) does not include DATEDIF.
10047032aefSPedro Giffuni
1014f909564SJim JagielskiERROR.TYPE (BIFF4 ID 261): reads as ocErrorTypeODF since 2026-11-18. Before
1024f909564SJim Jagielskithat it read as ocErrorType, so Excel files got AOO's internal error numbers.
1034f909564SJim Jagielski
1044f909564SJim JagielskiAll functions in saFuncTable_Oox (`_xlfn.` prefix) have NOID as BIFF
10547032aefSPedro Giffunifunction ID for import, meaning they cannot be imported via BIFF ID
10647032aefSPedro Giffunilookup. These are Excel future functions (Excel 2007/2010/2013+) that
10747032aefSPedro Giffunidon't exist in older BIFF versions. This is intentional.
10847032aefSPedro Giffuni
1094f909564SJim JagielskiAll functions in saFuncTable_Odf (`_xlfnodf.` prefix) have NOID as BIFF
11047032aefSPedro Giffunifunction ID for import, meaning they cannot be imported via BIFF ID
11147032aefSPedro Giffunilookup. These are ODF namespace functions not defined in BIFF. This is
11247032aefSPedro Giffuniintentional.
11347032aefSPedro Giffuni
1144f909564SJim JagielskiDDE has a native evaluator but no BIFF function ID in any AOO table.
11547032aefSPedro Giffuni
11647032aefSPedro GiffuniFunctions ODDFPRICE, ODDFYIELD are Analysis AddIn functions with no native
11747032aefSPedro Giffuniopcode. Classification: intentional limitation.
11847032aefSPedro Giffuni
11947032aefSPedro GiffuniFunction DDE has a native opcode and evaluator but is not a BIFF function.
12047032aefSPedro GiffuniClassification: intentional limitation.
12147032aefSPedro Giffuni
12247032aefSPedro GiffuniExport Findings
12347032aefSPedro Giffuni---------------
12447032aefSPedro Giffuni
1254f909564SJim JagielskiThe tables are filled in the order 2, 3, 4, 5, 8, Oox, Odf; for export a
1264f909564SJim Jagielskilater entry for the same opcode replaces an earlier one.
1274f909564SJim Jagielski
12847032aefSPedro GiffuniAll functions in saFuncTable_Oox have EXC_FUNCFLAG_EXPORTONLY entries with
12947032aefSPedro GiffuniBIFF ID 255 (future function marker). These are exported to BIFF as future
1304f909564SJim Jagielskifunctions using the `_xlfn.` name mechanism. Correct for OOXML future
13147032aefSPedro Giffunifunctions.
13247032aefSPedro Giffuni
13347032aefSPedro GiffuniAll functions in saFuncTable_Odf have EXC_FUNCFLAG_EXPORTONLY entries with
13447032aefSPedro GiffuniBIFF ID 255 (future function marker). These are exported to BIFF using the
1354f909564SJim Jagielski`_xlfnodf.` name mechanism. AOO reads them back; Excel shows #NAME? for them.
1364f909564SJim JagielskiUntil 2026-11-18 the ODF table listed ocFDist for "FDIST" and ocFInv for
1374f909564SJim Jagielski"FINV"; it now lists the left-tail ocFDistLeft/ocFInvLeft, which is what ODF
1384f909564SJim JagielskiFDIST/FINV mean.
13947032aefSPedro Giffuni
1404f909564SJim JagielskiDATEDIF has been written to BIFF ID 351 since 2026-11-18 (it was
1414f909564SJim Jagielskiimport-only), and Excel 16 calculates it. ERRORTYPE has an export-only 261
1424f909564SJim Jagielskientry, so it is written as ERROR.TYPE, as before; on reading it becomes
1434f909564SJim JagielskiERROR.TYPE.
14447032aefSPedro Giffuni
1454f909564SJim JagielskiHYPGEOMDIST is written as BIFF4 ID 289, which takes four arguments; a call
1464f909564SJim Jagielskiwith the fifth (Cumulative) argument is written as NA().
1474f909564SJim Jagielski
1484f909564SJim JagielskiFunctions in saFuncTable_2 (BIFF2 IDs 205-211 for B-functions) and
14947032aefSPedro GiffunisaFuncTable_4 (BIFF4 IDs 261-320) and saFuncTable_8 (BIFF8 ID 358) have
15047032aefSPedro Giffuniboth import and export mappings. Correct.
15147032aefSPedro Giffuni
15247032aefSPedro GiffuniRemaining ocNoName entries in BIFF tables:
1534f909564SJim Jagielski
15447032aefSPedro Giffuni- DATESTRING (BIFF5 ID 352): No native opcode. Intentional.
15547032aefSPedro Giffuni- NUMBERSTRING (BIFF5 ID 353): No native opcode. Intentional.
15647032aefSPedro Giffuni- PHONETIC (BIFF8 ID 360): No native opcode. Intentional.
15747032aefSPedro Giffuni
15847032aefSPedro GiffuniAdjacent Compatibility Layers
15947032aefSPedro Giffuni-----------------------------
16047032aefSPedro Giffuni
16147032aefSPedro GiffuniOOXML/XLSX mappings (saFuncTable_Oox) are separate from BIFF mappings and
1624f909564SJim Jagielskiuse `_xlfn.` prefix names with NOID/255 BIFF IDs. These are not confused with
16347032aefSPedro GiffuniBIFF support - NOID means no BIFF function ID exists.
16447032aefSPedro Giffuni
1654f909564SJim JagielskiODF namespace mappings (saFuncTable_Odf) use `_xlfnodf.` prefix names with
16647032aefSPedro GiffuniNOID/255 BIFF IDs. These are distinct from native BIFF function IDs.
16747032aefSPedro Giffuni
16847032aefSPedro GiffuniBIFF function IDs and Calc opcode IDs are distinct namespaces. BIFF ID 255
16947032aefSPedro Giffuniis used as a sentinel for "future function" in OOXML/OXDF namespace
17047032aefSPedro Giffunimappings, not as a real BIFF function ID for import purposes.
17147032aefSPedro Giffuni
1724f909564SJim JagielskiThe xlsx import is a separate table in oox/source/xls/formulabase.cxx. Since
1734f909564SJim Jagielski2026-11-18 it reads FINDB, SEARCHB, REPLACEB, DATEDIF and ERROR.TYPE (run
174*83f26b2aSJim Jagielskiwith a hand-made xlsx); `_xlfn.F.DIST`, `_xlfn.F.INV`, `_xlfn.NUMBERVALUE`, `_xlfn.RRI` and
175*83f26b2aSJim Jagielski`_xlfn.ISOWEEKNUM` are read too (run, hand-made xlsx).
1764f909564SJim Jagielski
17747032aefSPedro GiffuniDefects Found
17847032aefSPedro Giffuni-------------
17947032aefSPedro Giffuni
18047032aefSPedro Giffuni1. DATEDIF: BIFF5 ID 351 mapped to ocNoName → #NAME! on import. FIXED
1814f909564SJim Jagielski   in commit a330cbd51b (ocNoName → ocDateDif).
1824f909564SJim Jagielski2. FINDB, SEARCHB, REPLACEB had no BIFF mapping; FINDB came back from xls as
1834f909564SJim Jagielski   #MACRO? in AOO and #NAME? in Excel (run). FIXED 2026-11-18 (205-207).
1844f909564SJim Jagielski3. ISOWEEKNUM (ocIsoWeekNum) had no mapping; same symptom. FIXED 2026-11-18
1854f909564SJim Jagielski   (`_xlfn.ISOWEEKNUM`).
1864f909564SJim Jagielski4. ERROR.TYPE from Excel read as ERRORTYPE. FIXED 2026-11-18.
1874f909564SJim Jagielski5. Legacy FDIST and FINV have been written to xls as `_xlfnodf.FDIST` and
1884f909564SJim Jagielski   `_xlfnodf.FINV` since the 2011 OOo import (the ODF table is filled last and
1894f909564SJim Jagielski   overrode BIFF 281/282). Those names now import as FDIST and FINV, not as
1904f909564SJim Jagielski   F.DIST and F.INV (an xls written by the 11-16 build, run). FDIST and FINV
1914f909564SJim Jagielski   are now written as BIFF 281/282.
19247032aefSPedro Giffuni
19347032aefSPedro GiffuniFunctions Requiring Follow-up
19447032aefSPedro Giffuni-----------------------------
19547032aefSPedro Giffuni
1964f909564SJim Jagielski- HYPGEOMDIST with five arguments: no xls form (Excel 2010's HYPGEOM.DIST
1974f909564SJim Jagielski  would need its own export entry; one opcode has one export entry).
1984f909564SJim Jagielski- NUMBERVALUE, RRI: written under `_xlfnodf.` names, which Excel does not
1994f909564SJim Jagielski  know; Excel 2013 has both.
2004f909564SJim Jagielski- F.DIST with three arguments: written as `_xlfn.F.DIST`, which Excel shows as
2014f909564SJim Jagielski  #N/A because it needs four.
20247032aefSPedro Giffuni
20347032aefSPedro GiffuniStatistics
20447032aefSPedro Giffuni----------
2054f909564SJim Jagielski
2064f909564SJim Jagielski- Total rows: 32
2074f909564SJim Jagielski- Correct mappings: 28
2084f909564SJim Jagielski- Limitations: 4 (DDE, ODDFPRICE, ODDFYIELD intentional; HYPGEOMDIST with 5 args)
2094f909564SJim Jagielski- Functions with native evaluators but no BIFF mapping: 1 (DDE)
21047032aefSPedro Giffuni- Functions implemented via AddIn (no native opcode): 2 (ODDFPRICE, ODDFYIELD)
21147032aefSPedro Giffuni
21247032aefSPedro GiffuniSource References
21347032aefSPedro Giffuni-----------------
2144f909564SJim Jagielski
21547032aefSPedro Giffuni- BIFF function tables: main/sc/source/filter/excel/xlformula.cxx
2164f909564SJim Jagielski  - saFuncTable_2: lines 74-221
2174f909564SJim Jagielski  - saFuncTable_3: lines 224-249
2184f909564SJim Jagielski  - saFuncTable_4: lines 252-326
2194f909564SJim Jagielski  - saFuncTable_5: lines 329-350
2204f909564SJim Jagielski  - saFuncTable_8: lines 353-368
2214f909564SJim Jagielski  - saFuncTable_Oox: lines 371-403
2224f909564SJim Jagielski  - saFuncTable_Odf: lines 410-439
2234f909564SJim Jagielski- Import path: FillXclFuncMap(), line 492
2244f909564SJim Jagielski- Export path: FillScFuncMap(), line 506
22547032aefSPedro Giffuni- Opcode definitions: main/formula/inc/formula/compiler.hrc
22647032aefSPedro Giffuni- Opcode enum: main/formula/inc/formula/opcode.hxx
22747032aefSPedro Giffuni- Function name registration: main/formula/source/core/resource/core_resource.src
22847032aefSPedro Giffuni- Evaluator dispatch: main/sc/source/core/tool/interpr4.cxx
2294f909564SJim Jagielski- xlsx import table: main/oox/source/xls/formulabase.cxx
230