{
  "category": "Text functions",
  "display_name": "REPT",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.REPT",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 12 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 12 recorded answers",
    "workbook_corpus": {
      "cells": 12,
      "matched": 12
    }
  },
  "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/text_functions.rs#L291-L295",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/ported/text_kernels.rs#L423-L440"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "ported/text_kernels::text"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/text_functions.rs#L291-L295",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 12 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.REPT.json",
  "name": "REPT",
  "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\n- **`CONCAT` / `TEXTJOIN` / the `&` operator** are the general concatenation route; `REPT` is\n  the special case where all the pieces are the same and the count is computed.\n- **[TEXTJOIN](FUNC.TEXTJOIN.md)** shares the 32,767-character result ceiling and the `#VALUE!`\n  on exceeding it, and is the other text function most likely to hit it.\n- **`LEN`** is the natural companion, both for predicting the cap and for the classic in-cell\n  bar-chart idiom `REPT(\"|\", value)`.\n- There is no compatibility-replacement pair here: `REPT` is neither superseded nor a retained\n  legacy name.\n- Readers occasionally confuse `REPT` with `SUBSTITUTE` when trying to pad strings. Padding is\n  `REPT` plus `LEN`; `SUBSTITUTE` has nothing to do with it.\n\n\n",
    "how-to-implement": "\n### Notes for implementers\n\n\nThe cap check must precede the allocation, not follow it. `REPT(\"x\", 10^9)` is a documented\n`#VALUE!`, and an implementation that discovers this by building the string first has a\ndenial-of-service surface where Excel has an error value. Compute `LEN(text) ×\nTRUNC(number_times)`, compare against 32,767, and only then allocate.\n\nThat multiplication itself needs care: `number_times` arrives as a double and can be\nastronomically large, so the length computation has to be done in a form that cannot overflow\nbefore the comparison happens.\n\nTruncation is toward zero, which is what makes the negative case a real question rather than a\nformality — `TRUNC(-0.5)` is 0, so a naive truncate-then-loop implementation would return the\nempty string for `REPT(\"a\", -0.5)` and something else for `REPT(\"a\", -1)`. Whatever Excel does,\nan implementation should not arrive at two different answers for those two inputs by accident.\n\nCounting is in UTF-16 code units against the cap, consistent with `LEN`.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Text`.\n\nDocumented:\n\n- `number_times` of 0 returns the empty string `\"\"`.\n- Non-integer `number_times` is truncated.\n- A result longer than 32,767 characters returns `#VALUE!`.\n\nNot documented, and therefore not stated as fact here: what a **negative** `number_times`\ndoes. Microsoft's page describes the argument as \"a positive number\" and states the zero case,\nbut does not state the negative case. `#VALUE!` is the obvious expectation and the obvious\nthing to probe.\n\nAlso undocumented: what `REPT(\"\", n)` does for large `n` — the result is empty regardless, but\nwhether the cap check runs before or after the empty-string shortcut decides whether\n`REPT(\"\", 10^9)` is instant or is an error.\n\n\n### Errors\n\n\n| Error | Condition | Source |\n|---|---|---|\n| `#VALUE!` | The result would exceed 32,767 characters. | Documented on Microsoft's `REPT` page. |\n| `#VALUE!` | Non-numeric text in `number_times`, or a value that cannot convert to text in `text`. | Shared coercion rules, not `REPT`-specific. |\n\nError values in either argument propagate. Whether a negative `number_times` produces\n`#VALUE!` or `#NUM!` is unverified — see above.\n\nThe over-cap rule deserves emphasis because the same cap behaves differently on a different\npath. The Handbook's value-universe chapter records that assigning an over-cap string through\nthe automation interface **truncates silently**, while producing one in a formula errors. Same\nlimit, two enforcement behaviours, decided by how the string arrives. `REPT` is on the erroring\nside.\n\n\n",
    "sources": "\n- Microsoft, \"REPT function\" —\n  <https://support.microsoft.com/en-us/office/rept-function-04c4d778-e712-43b4-9c15-d656582bb061>\n  (signature, the zero case, the truncation rule, and the 32,767-character `#VALUE!`).\n- Handbook, [The value universe](../model/01-value-universe.md) — the text cap in UTF-16 code\n  units, the observed `#VALUE!` on the over-cap formula path (observed with `REPT`), and the\n  contrasting silent truncation on the interop path.\n- Handbook, [Coercion and lifting](../model/02-coercion-and-lifting.md) — to-number and to-text\n  coercion of the two argument slots.\n- Handbook projections `data/functions/FUNC.REPT.json` (placeholder signature) and\n  `data/presence/FUNC.REPT.json` (implementing module; `BUG-FUNC-008`).\n\n",
    "version-differences": "No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.",
    "what-it-does": "\n`REPT(text, number_times)` returns `text` concatenated with itself `number_times` times:\n\n```\nREPT(t, n)  =  t · t · … · t     (n copies)\nREPT(t, 0)  =  \"\"\n```\n\n`number_times` is truncated to an integer before use — Microsoft states this explicitly — so\n`REPT(\"ab\", 2.9)` is `REPT(\"ab\", 2)`.\n\nThe interesting property of this function is not the concatenation. It is that `REPT` is the\ncheapest way in the whole worksheet language to manufacture a string longer than Excel will\nhold, which makes it the function against which the text cap is most often observed. The\nHandbook's value-universe chapter records that observation: producing an over-cap string in a\nformula yields `#VALUE!`, and `REPT` is the function it was observed with.\n\nThe result length is `LEN(text) × TRUNC(number_times)` code units, and the documented ceiling\nis 32,767.\n\n\n\n### Arguments\n\n\n| Argument | Meaning |\n|---|---|\n| `text` | The string to repeat. Required. |\n| `number_times` | How many copies. Required; documented as a positive number, truncated to an integer. |\n\n`number_times` is a numeric slot and takes ordinary to-number coercion; see\n[Coercion and lifting](../model/02-coercion-and-lifting.md). `text` may be any value that\nconverts to text, so `REPT(0, 3)` is a to-text question before it is a `REPT` question.\n\n\n"
  },
  "signature": {
    "display": "REPT(text, number_times)",
    "parameters": [
      {
        "description": null,
        "name": "text",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "number_times",
        "optional": false,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 2,
        "min": 2
      },
      "category": "Text functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "None",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "None",
        "host_interaction_class": "None",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "A text repeated a number of times",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Repeats text a given number of times",
        "microsoft_url": "https://support.microsoft.com/en-us/office/rept-function-04c4d778-e712-43b4-9c15-d656582bb061"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "REPT"
        },
        {
          "locale": "bg-BG",
          "name": "REPT"
        },
        {
          "locale": "cs-CZ",
          "name": "OPAKOVAT"
        },
        {
          "locale": "da-DK",
          "name": "GENTAG"
        },
        {
          "locale": "de-DE",
          "name": "REPT"
        },
        {
          "locale": "el-GR",
          "name": "REPT"
        },
        {
          "locale": "en-AU",
          "name": "REPT"
        },
        {
          "locale": "en-GB",
          "name": "REPT"
        },
        {
          "locale": "en-US",
          "name": "REPT"
        },
        {
          "locale": "es-ES",
          "name": "REPT"
        },
        {
          "locale": "et-EE",
          "name": "REPT"
        },
        {
          "locale": "fi-FI",
          "name": "TOISTA"
        },
        {
          "locale": "fr-FR",
          "name": "REPT"
        },
        {
          "locale": "he-IL",
          "name": "REPT"
        },
        {
          "locale": "hr-HR",
          "name": "REPT"
        },
        {
          "locale": "hu-HU",
          "name": "SOKSZOR"
        },
        {
          "locale": "id-ID",
          "name": "REPT"
        },
        {
          "locale": "it-IT",
          "name": "REPT"
        },
        {
          "locale": "ja-JP",
          "name": "REPT"
        },
        {
          "locale": "ko-KR",
          "name": "REPT"
        },
        {
          "locale": "lt-LT",
          "name": "REPT"
        },
        {
          "locale": "lv-LV",
          "name": "REPT"
        },
        {
          "locale": "nb-NO",
          "name": "GJENTA"
        },
        {
          "locale": "nl-NL",
          "name": "HERHALING"
        },
        {
          "locale": "pl-PL",
          "name": "POWT"
        },
        {
          "locale": "pt-BR",
          "name": "REPT"
        },
        {
          "locale": "pt-PT",
          "name": "REPETIR"
        },
        {
          "locale": "ro-RO",
          "name": "REPT"
        },
        {
          "locale": "ru-RU",
          "name": "ПОВТОР"
        },
        {
          "locale": "sk-SK",
          "name": "REPT"
        },
        {
          "locale": "sl-SI",
          "name": "REPT"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "REPT"
        },
        {
          "locale": "sv-SE",
          "name": "REP"
        },
        {
          "locale": "th-TH",
          "name": "REPT"
        },
        {
          "locale": "tr-TR",
          "name": "YİNELE işlevi"
        },
        {
          "locale": "uk-UA",
          "name": "REPT"
        },
        {
          "locale": "vi-VN",
          "name": "REPT"
        },
        {
          "locale": "zh-CN",
          "name": "REPT"
        },
        {
          "locale": "zh-HK",
          "name": "REPT"
        },
        {
          "locale": "zh-TW",
          "name": "REPT"
        }
      ],
      "signature": {
        "display": "REPT(text, number_times)",
        "parameters": [
          {
            "description": null,
            "name": "text",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "number_times",
            "optional": false,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "REPT",
      "version_marker": null,
      "xlcall": {
        "code": "30",
        "symbol": "xlfRept"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/rept-function-04c4d778-e712-43b4-9c15-d656582bb061"
  },
  "try_it": {
    "formula": "=REPT(\"ab\", 2.9)"
  },
  "url": "https://handbook.dnacalc.com/functions/REPT.html",
  "variants": [],
  "versions": []
}