{
  "category": "Math and trigonometry functions",
  "display_name": "SEC",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.SEC",
  "implementation_state": {
    "answer_bank": {
      "excel_builds": [
        "20131",
        "20430",
        "?"
      ],
      "larger_numeric": 0,
      "last_bit": 0,
      "matched": 2138,
      "other_mismatch": 0,
      "refused": 0,
      "rows": 2138,
      "unread": 0,
      "worst_ulp": 0
    },
    "detail": "Recorded: 2,138 in the answer bank and 3 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 2,141 recorded answers",
    "workbook_corpus": {
      "cells": 3,
      "matched": 3
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/math.rs#L70-L70",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/ported/sec.rs#L4-L12"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/math::unary",
        "ported/excel_numeric::binary_with",
        "ported/excel_numeric::cos_with",
        "ported/excel_numeric::excel_cos",
        "ported/excel_numeric::excel_x87_recip",
        "ported/excel_numeric/soft87::pack_raw",
        "ported/excel_numeric/soft87::zero",
        "ported/excel_numeric/soft87::inf",
        "ported/excel_numeric/soft87::pack",
        "ported/excel_numeric/soft87::ext_pi",
        "ported/excel_numeric/soft87::ext_one",
        "ported/excel_numeric/soft87::ext_abs",
        "ported/excel_numeric/soft87::ext_chs",
        "ported/excel_numeric/x87::recip"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/math.rs#L70-L70",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 2,141 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.SEC.json",
  "name": "SEC",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n- **`CSC` and `COT`** — the other two reciprocals, of `SIN` and `TAN`. All three share the\n  `2²⁷` guard, all three are built on two kernels, and all three carry the same host-CPU caveat.\n- **`TAN`** — related by `sec²x = 1 + tan²x`, which is the numerically preferable route to `sec`\n  when `tan` is already available and `x` is near a pole: computing `sqrt(1 + tan²x)` avoids the\n  division by a tiny cosine, at the cost of losing the sign, which must be restored from the\n  quadrant.\n- **[SECH](FUNC.SECH.md)** — the hyperbolic namesake, and a completely different function: bounded,\n  pole-free, and with no argument limit. The two are related only through the complex identity\n  `sech(x) = sec(ix)`.\n- **`ACOS`** — there is no `ASEC`. The inverse secant must be written `ACOS(1/x)`, which is defined\n  for `|x| ≥ 1` and inherits a division by the argument.\n- **[RADIANS](FUNC.RADIANS.md)** — the usual upstream converter, and, given the amplification\n  below, a genuine contributor to the error of the result.\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n**The condition number is the whole story.** Differentiating, the relative error in `sec x`\nproduced by a relative error `ε` in `x` is\n\n    |x · d(sec x)/dx / sec x| · ε  =  |x · tan x| · ε\n\nso the amplification factor is `|x tan x|`, which is unbounded as `x` approaches a pole. Near\n`π/2`, a last-bit perturbation of the argument moves the result by an arbitrarily large relative\namount. This is not an implementation weakness; it is a property of the function, and it means that\n**no implementation can return an accurate secant near a pole from an inexact argument**. The\nhonest response is to say so, which most libraries do not.\n\n**Argument reduction is where the accuracy is won or lost.** Evaluating `cos x` requires `x mod\n2π`, and the modulus must be taken against the real π rather than against `fl(π)` — every bit by\nwhich `|x|` exceeds π costs a bit of the reduced argument if the reduction uses a rounded constant.\nThe standard remedy is Payne–Hanek reduction against a many-word 2/π, as implemented in fdlibm's\n`__ieee754_rem_pio2`; it is exact for every finite double and costs a bounded amount of work.\n\nExcel's recorded behaviour is the alternative policy: **refuse**. A cutoff at `2²⁷` is\napproximately where a reduction using a double-precision π begins to lose the low half of the\nreduced argument, so the threshold reads as the point at which the implementer stopped trusting\ntheir own reduction. The Handbook's position is that both are defensible engineering, that only one\nof them is documented (neither), and that a `natural-best` implementation should reduce correctly\nand return a value where Excel returns an error — which is a deliberate, declared divergence, not a\ncompatibility bug. See [About implementation options](../model/07-implementation-options.md).\n\n**Host-CPU dependence.** `EV-MATH-0004`'s reader warning records that all six circular surfaces\ninherit a host-CPU microcode caveat on the x87 `FPREM1`, `FSIN` and `FPTAN` instructions. In plain\nterms: the value may depend on which processor evaluates it. That is a `portable-reproducible`\nconcern, and it is the reason a suite for this function would have to name a CPU as well as an\nExcel build.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Number`.\n\n- **`SEC(0)` is exactly 1**, and it is one of the few inputs where an exact answer is available.\n- **Near a pole the result is enormous and its accuracy is not.** As `x` approaches `π/2` the\n  returned value grows without bound; the *relative* accuracy of that value degrades in proportion\n  to how well the argument's last bits locate `x` relative to the pole. See the numerical notes.\n\n\n\n### Errors\n\n\n| Error | Condition | Source |\n|---|---|---|\n| `#NUM!` | `\\|number\\| ≥ 2²⁷` | observed live Excel, catalogue `XMD-005`; **not documented** |\n| `#VALUE!` | The argument does not convert to a number | shared coercion model |\n| propagated | The argument is an error value | shared coercion model |\n\nMicrosoft's documentation states none of these.\n\n\n",
    "sources": "- Microsoft, \"WorksheetFunction.Sec method (Excel)\" —\n  <https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.sec> (the entire\n  documented content: description, one argument, return type; **no remarks, no domain limit, no\n  errors**).\n- Handbook evidence record `EV-MATH-0004`, rendered beside this page with its own reader warning.\n- Abramowitz & Stegun, *Handbook of Mathematical Functions*, section 4.3 — circular functions,\n  the Euler-number series and the pole structure.\n- Payne & Hanek, SIGNUM Newsletter 18 (1983); fdlibm `__ieee754_rem_pio2`; Muller, *Elementary\n  Functions: Algorithms and Implementation*.\n- Handbook, [RADIANS](FUNC.RADIANS.md), [SECH](FUNC.SECH.md),\n  [Coercion and lifting](../model/02-coercion-and-lifting.md),\n  [About implementation options](../model/07-implementation-options.md).\n- Handbook projections `data/functions/FUNC.SEC.json`\n  (`arg_domain_guard=circular_trig_overflow`, `non_finite=num`) and\n  `data/presence/FUNC.SEC.json` (own module; one math-deviation mention; no defect streams).\n\n",
    "version-differences": "The recorded environments below distinguish a reading from a same-input comparison. Counts describe captured inputs in each environment; overlapping captures and comparisons are not totals of unique worksheet calls.\n\n| Excel 16.0 build | Platform and CPU | Captured inputs |\n|---|---|---:|\n| 19929 | Windows, bitness not recorded, CPU not recorded | 33 |\n| 20131 | Windows, bitness not recorded, AMD Ryzen 7 4800H with Radeon Graphics | 914 |\n| 20430 | Windows, 64-bit, CPU not recorded | 1,224 |\n\n- XC-SEC-001: build 19929 versus build 20430; 1 same-input pairs, 0 differing answers. Compared axes: excel-build. Numeric answers were compared by their recorded binary64 bits; other answers by typed value.\n- XC-SEC-002: build 20131 versus build 20430; 1 same-input pairs, 0 differing answers. Compared axes: excel-build. Numeric answers were compared by their recorded binary64 bits; other answers by typed value.\n\nAgreement on these compared inputs does not establish agreement on unmeasured inputs.\n\n[Recorded environments and comparison details](https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.SEC.json).",
    "what-it-does": "\n`SEC(number)` returns the secant of an angle given in radians.\n\n    sec x = 1 / cos x\n\n**Domain.** All real `x` except the zeros of cosine, `x = π/2 + kπ` for integer `k`, where secant\nhas simple poles. **Range.** `|sec x| ≥ 1`: the values `(−1, 1)` are never attained. The function\nis even, `2π`-periodic, and satisfies the Pythagorean identity\n\n    sec²x − tan²x = 1\n\nIts derivative is `sec x · tan x`, and its Maclaurin series is the Euler-number generating function\n\n    sec x = Σ_{n≥0} |E_{2n}| x^{2n} / (2n)!  =  1 + x²/2 + 5x⁴/24 + 61x⁶/720 + …\n\nconvergent for `|x| < π/2` — the radius is exactly the distance to the nearest pole, which is the\ncompact statement of why this function is hard near `π/2`. (A&S 4.3.68.)\n\n**A fact worth stating before the numerics.** No binary64 value is exactly `π/2 + kπ`, because\nthose points are irrational. So `SEC` never actually divides by zero on a machine: it divides by a\nvery small number and returns a very large one. The pole is unreachable, and everything difficult\nabout the function happens in its neighbourhood rather than at it.\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Default |\n|---|---|---|\n| `number` | The angle, **in radians**, whose secant is wanted. Required. | — |\n\nDegrees must be converted first: `SEC(RADIANS(d))`. See [RADIANS](FUNC.RADIANS.md) for what that\nconversion costs, which matters more here than for most consumers because of the amplification\ndescribed below.\n\nMicrosoft's VBA page for this method is three lines long: a one-sentence description, the single\nargument, the return type. **No remarks, no domain restriction, no error condition.**\n\n\n"
  },
  "signature": {
    "display": "SEC(number)",
    "parameters": [
      {
        "description": null,
        "name": "number",
        "optional": false,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 1,
        "min": 1
      },
      "category": "Math and trigonometry functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "UnaryNumericScalarOrArrayElementwise",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "None",
        "host_interaction_class": "None",
        "kernel_signature_class": "NumToNum",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "Secant of an angle in radians",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns the secant of an angle",
        "microsoft_url": "https://support.microsoft.com/en-us/office/sec-function-ff224717-9c87-4170-9b58-d069ced6d5f7"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "SEC"
        },
        {
          "locale": "bg-BG",
          "name": "SEC"
        },
        {
          "locale": "cs-CZ",
          "name": "SEC"
        },
        {
          "locale": "da-DK",
          "name": "SEC"
        },
        {
          "locale": "de-DE",
          "name": "SEC"
        },
        {
          "locale": "el-GR",
          "name": "SEC"
        },
        {
          "locale": "en-AU",
          "name": "SEC"
        },
        {
          "locale": "en-GB",
          "name": "SEC"
        },
        {
          "locale": "en-US",
          "name": "SEC"
        },
        {
          "locale": "es-ES",
          "name": "SEC"
        },
        {
          "locale": "et-EE",
          "name": "SEC"
        },
        {
          "locale": "fi-FI",
          "name": "SEK"
        },
        {
          "locale": "fr-FR",
          "name": "SEC*"
        },
        {
          "locale": "he-IL",
          "name": "SEC"
        },
        {
          "locale": "hr-HR",
          "name": "SEC"
        },
        {
          "locale": "hu-HU",
          "name": "SEC"
        },
        {
          "locale": "id-ID",
          "name": "SEC"
        },
        {
          "locale": "it-IT",
          "name": "SEC"
        },
        {
          "locale": "ja-JP",
          "name": "SEC"
        },
        {
          "locale": "ko-KR",
          "name": "SEC"
        },
        {
          "locale": "lt-LT",
          "name": "SEC"
        },
        {
          "locale": "lv-LV",
          "name": "SEC"
        },
        {
          "locale": "nb-NO",
          "name": "SEC"
        },
        {
          "locale": "nl-NL",
          "name": "SECONDE"
        },
        {
          "locale": "pl-PL",
          "name": "SEC"
        },
        {
          "locale": "pt-BR",
          "name": "SEC"
        },
        {
          "locale": "pt-PT",
          "name": "SEC"
        },
        {
          "locale": "ro-RO",
          "name": "SEC"
        },
        {
          "locale": "ru-RU",
          "name": "SEC"
        },
        {
          "locale": "sk-SK",
          "name": "SEC"
        },
        {
          "locale": "sl-SI",
          "name": "SEC"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "SEC"
        },
        {
          "locale": "sv-SE",
          "name": "SEK"
        },
        {
          "locale": "th-TH",
          "name": "SEC"
        },
        {
          "locale": "tr-TR",
          "name": "SEC"
        },
        {
          "locale": "uk-UA",
          "name": "SEC"
        },
        {
          "locale": "vi-VN",
          "name": "SEC"
        },
        {
          "locale": "zh-CN",
          "name": "SEC"
        },
        {
          "locale": "zh-HK",
          "name": "SEC"
        },
        {
          "locale": "zh-TW",
          "name": "SEC"
        }
      ],
      "signature": {
        "display": "SEC(number)",
        "parameters": [
          {
            "description": null,
            "name": "number",
            "optional": false,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "SEC",
      "version_marker": null,
      "xlcall": {
        "code": "554",
        "symbol": "xlfSec"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/sec-function-ff224717-9c87-4170-9b58-d069ced6d5f7"
  },
  "try_it": {
    "formula": "=SEC(0)"
  },
  "url": "https://handbook.dnacalc.com/functions/SEC.html",
  "variants": [],
  "versions": [
    {
      "behaviour": "33 captured inputs are indexed for this environment. Capture dates are not recorded. This is a reading count, not a comparison with another build.",
      "excel_build": "16.0 build 19929",
      "platform": "Windows, bitness not recorded, CPU not recorded",
      "sources": [
        "https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.SEC.json"
      ]
    },
    {
      "behaviour": "914 captured inputs are indexed for this environment. Capture dates: 2026-07-11 to 2026-07-11. This is a reading count, not a comparison with another build.",
      "excel_build": "16.0 build 20131",
      "platform": "Windows, bitness not recorded, AMD Ryzen 7 4800H with Radeon Graphics",
      "sources": [
        "https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.SEC.json"
      ]
    },
    {
      "behaviour": "1,224 captured inputs are indexed for this environment. Capture dates: 2026-09-29 to 2026-09-29. This is a reading count, not a comparison with another build.",
      "excel_build": "16.0 build 20430",
      "platform": "Windows, 64-bit, CPU not recorded",
      "sources": [
        "https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.SEC.json"
      ]
    }
  ]
}