## overflow checking

Generally, all the code in the standard library and elsewhere is written without inserting any overflow checking.  Unless you have a special need, don't worry about it in your functions.

Now that it's a template, the caller could specify an extended-precision integer class, or a "safe" integer class, to get such checking.  The checking is _part of the type_ used, and need not be explicitly addressed in your code.  It will be built into the `operator+` etc. for that type.  For example, see the videos from the 2021 [C++now](https://www.youtube.com/user/BoostCon/videos) conference — I recall a presentation on _Simplest Safe Integers_, and there have been others in the past.

## parameter, return, and other types

> Another point of concern is for templatized argument, I am forced to use the same type as the return type, which means the mean of integers shall also result in an integer, clearly not a good choice. At the same time if I enforce double as the return type, then extending into multi-dimensional types like vectors or complex numbers will be problematic.

No, you are **not** forced to use the same type for the argument as the return.

You can take the input parameter as _another_ template argument.  Using classic syntax:

```
template <typename R, typename P>
R factorial (P x)
{ ⋯ }
```

With C++20, you can use Concepts to specify that the template parameters must be integral types.

Note that you put `R` first, since you will deduce `P` from the arguments but must give `R`.  Example use:

```
const auto y = factorial<bignum_t>(432);
```

Likewise, you can take additional template arguments, perhaps with defaults, to use for internal computations if that becomes necessary.

It's probably much more efficient to use built-in integers for inputs and where you can inside the body of the function, and the extended-precision (or "safe") class for the accumulation of the result.

## comparison for floating-point

That should be built-into the unit testing framework.  ([example](https://github.com/catchorg/Catch2/blob/devel/docs/matchers.md#floating-point-matchers))

# the new functions

_to be continued_