TIP 745: Functions from C99

Login
Bounty program for improvements to Tcl and certain Tcl packages.
 Author:         Donal K. Fellows <dkf@users.sf.net>
 State:          Draft
 Type:           Project
 Tcl-Version:    9.1
 Vote:           In progress
 Created:        03-Jan-2026
 Keywords:       Tcl
 Tcl-Branch:     c11-functions

Abstract

C99 has many more standard functions than C89. We should give Tcl scripts access to that bounty.

Rationale

C99 has many functions for mathematical work, not all of which are already exposed (despite 521 covering a fair chunk of the space). We ought to make these available to Tcl scripts as the cost of doing so is generally very small.

Note that this set of functions does not substantially change between C99 and later versions of the C Standard (C11, C17 and C23).

Specification

The following commands are added to the tcl::mathfunc namespace, typically with an obvious mapping to the list on this page (after ignoring the complexities due to the different type system in C relative to Tcl):

  • acosh
  • asinh
  • atanh
  • cbrt
  • copysign
  • dim — this is the fdim() function, but Tcl has no need to use an f prefix.
  • erf
  • erfc
  • exp2
  • expm1
  • fma
  • gamma — this is the tgamma() function, but Tcl has no ambiguity requiring using the t prefix.
  • ldexp
  • lgamma
  • log1p
  • log2
  • logb
  • nextafter
  • remainder
  • signbit — this is extended to cover all Tcl numeric values.
  • trunc

In addition, these commands are added to the global namespace to represent functions that conceptually return multiple values:

  • divmod — this is like the div() function, but uses Tcl's integer division rules and supports bignums.
  • frexp
  • modf
  • remquo

Omitted Functions

The following are omitted for various reasons.

  • nan() — Tcl recognises NaN directly.
  • nearbyint() — Tcl doesn't currently support setting the rounding mode.
  • rint() — Tcl doesn't currently support setting the rounding mode.
  • scalbn() — Would be equivalent to ldexp on platforms we support.
  • ilogb() — A differently-typed logb.
  • nexttoward() — A differently-typed nextafter.
  • isgreater(), isless(), etc. — Not sure if required; Tcl prefers to raise an error on NaN.

Implementation

See the c11-functions branch.

Copyright

This document has been placed in the public domain.

History