Skip to content

ans [terminology]

Terminology

Usage

  • Use for a generic final scalar answer when no concise semantic name is better.
  • It commonly holds the accumulated answer in a short mathematical algorithm.
  • Unlike res, it normally does not suggest a collection being assembled.
  • Prefer best, cnt, total, rev, or another semantic name when one precisely describes the value.
ans = 1.0
base = x
while n > 0:
    if n & 1:
        ans *= base
    base *= base
    n >>= 1

See 50. Pow(x, n).