TIP 745: Functions from C11
This is TIP #745. This branch adds more mathematical functions from the set listed here.
New global commands
These all return multiple values, which expr doesn't like but lassign does.
- divmod — this is like the
div()function, but uses Tcl's integer division rules and supports bignums. - frexp
- modf
- remquo
New functions (commands in tcl::mathfunc)
- acosh
- asinh
- atanh
- cbrt
- copysign
- dim — this is the
fdim()function, but Tcl has no need to use anfprefix so it uses the name from Fortran. - erf
- erfc
- exp2
- expm1
- fma
- gamma — this is the
tgamma()function, but Tcl has no ambiguity requiring using thetprefix. - ldexp
- lgamma
- log1p
- log2
- logb
- nextafter
- remainder
- signbit — this is extended to cover all Tcl numeric values.
- trunc
The full list
After removing the type-dupes, as Tcl doesn't do those.
Basic operations
| C Name | Description | Tcl notes |
|---|---|---|
| div | computes quotient and remainder of integer division | This branch: [div] command |
| fabs | computes absolute value of a floating-point value (|x|) | Existing: abs() function |
| fmod | computes remainder of the floating-point division operation | Existing: fmod() function |
| remainder | computes signed remainder of the floating-point division operation | This branch: remainder() function |
| remquo | computes signed remainder as well as the three last bits of the division operation | This branch: [remquo] command |
| fma | computes fused multiply-add operation; (x*y)+z | This branch: fma() function |
| fmax | determines larger of two floating-point values | Existing: max() function |
| fmin | determines smaller of two floating-point values | Existing: min() function |
| fdim | determines positive difference of two floating-point values (max(0, x-y)) | This branch: dim() function (see C notes re Fortran heritage for the name change reason) |
| nan | returns a NaN (not-a-number) | Existing: direct understanding (usually as an error) |
Exponential functions
| C Name | Description | Tcl notes |
|---|---|---|
| exp | computes e raised to the given power (ex) | Existing: exp() function |
| exp2 | computes 2 raised to the given power (2x) | This branch: exp2() function |
| expm1 | computes e raised to the given power, minus one (ex-1) | This branch |
| log | computes natural (base-e) logarithm (ln(x)) | Existing: log() function |
| log10 | computes common (base-10) logarithm (log10(x)) | Existing: log10() function |
| log2 | computes base-2 logarithm (log2(x)) | This branch: log2() function |
| log1p | computes natural (base-e) logarithm of 1 plus the given number (ln(1+x)) | This branch: log1p() function |
Power functions
| C Name | Description | Tcl notes |
|---|---|---|
| pow | computes a number raised to the given power (xy) | Existing: pow() function and ** operator |
| sqrt | computes square root (√x) | Existing: sqrt() function |
| cbrt | computes cube root (3√x) | This branch: cbrt() function |
| hypot | computes square root of the sum of the squares of two given numbers (√(x2+y2)) | Existing: hypot() function |
Trigonometric functions
| C Name | Description | Tcl notes |
|---|---|---|
| sin | computes sine (sin(x)) | Existing: sin() function |
| cos | computes cosine (cos(x)) | Existing: cos() function |
| tan | computes tangent (tan(x)) | Existing: tan() function |
| asin | computes arc sine (sin-1(x)) | Existing: asin() function |
| acos | computes arc cosine (cos-1(x)) | Existing: acos() function |
| atan | computes arc tangent (tan-1(x)) | Existing: atan() function |
| atan2 | computes arc tangent, using signs to determine quadrants | Existing: atan2() function |
Hyperbolic functions
| C Name | Description | Tcl notes |
|---|---|---|
| sinh | computes hyperbolic sine (sinh(x)) | Existing: sinh() function |
| cosh | computes hyperbolic cosine (cosh(x)) | Existing: cosh() function |
| tanh | computes hyperbolic tangent (tanh(x)) | Existing: tanh() function |
| asinh | computes inverse hyperbolic sine (sinh-1(x)) | This branch: asinh() function |
| acosh | computes inverse hyperbolic cosine (cosh-1(x)) | This branch: acosh() function |
| atanh | computes inverse hyperbolic tangent (tanh-1(x)) | This branch: atanh() function |
Error and gamma functions
| C Name | Description | Tcl notes |
|---|---|---|
| erf | computes error function | This branch: erf() function |
| erfc | computes complementary error function | This branch: erfc() function |
| tgamma | computes gamma function | This branch: gamma() function (see C notes for why the rename) |
| lgamma | computes natural (base-e) logarithm of the gamma function | This branch: lgamma() function |
Nearest integer floating-point operations
| C Name | Description | Tcl notes |
|---|---|---|
| ceil | computes smallest integer not less than the given value | Existing: ceil() function |
| floor | computes largest integer not greater than the given value | Existing: floor() function |
| trunc | rounds to nearest integer not greater in magnitude than the given value | This branch: trunc() function |
| round | rounds to nearest integer, rounding away from zero in halfway cases | Existing: round() function |
| nearbyint | rounds to an integer using current rounding mode | Not implemented: no rounding mode control in Tcl |
| rint | rounds to an integer using current rounding mode with exception if the result differs | Not implemented: no rounding mode control in Tcl |
Floating-point manipulation functions
| C Name | Description | Tcl notes |
|---|---|---|
| frexp | breaks a number into significand and a power of 2 | This branch: [frexp] command |
| ldexp | multiplies a number by 2 raised to a power | This branch: ldexp() function |
| modf | breaks a number into integer and fractional parts | This branch: [modf] command |
| scalbn | computes efficiently a number times FLT_RADIX raised to a power |
Tcl only supports FLT_RADIX==2 systems, so frexp() equivalent |
| ilogb | extracts exponent of the given number | Not sure why this is exists... |
| logb | extracts exponent of the given number | This branch: logb() function |
| nextafter | determines next representable floating-point value towards the given value | This branch: nextafter() function |
| copysign | produces a value with the magnitude of a given value and the sign of another given value | This branch: copysign() function |
Classification and comparison
| C Name | Description | Tcl notes |
|---|---|---|
| fpclassify | classifies the given floating-point value | Existing: fpclassify command |
| isfinite | checks if the given number has finite value | Existing: isfinite() function |
| isinf | checks if the given number is infinite | Existing: isinf() function |
| isnan | checks if the given number is NaN | Existing: isnan() function |
| isnormal | checks if the given number is normal | Existing: isnormal() function |
| signbit | checks if the given number is negative | This branch: signbit() function |
| isgreater | checks if the first floating-point argument is greater than the second | |
| isgreaterequal | checks if the first floating-point argument is greater or equal than the second | |
| isless | checks if the first floating-point argument is less than the second | |
| islessequal | checks if the first floating-point argument is less or equal than the second | |
| islessgreater | checks if the first floating-point argument is less or greater than the second | |
| isunordered | checks if two floating-point values are unordered | Existing: isunordered() function |
28 check-ins related to "c11-functions"
|
2026-05-04
| ||
| 13:16 | Implement TIP 745: Functions from C99 check-in: 4a1dec85e7 user: dkf tags: trunk, main | |
|
2026-04-26
| ||
| 10:35 | merge trunk closed check-in: a17abd2d49 user: dkf tags: c11-functions | |
| 03:55 | Sync win/rules-ext.vc and win/rules.vc up with other projects; remove debug messages. check-in: 411b57c37b user: PHILB tags: trunk, main | |
|
2026-04-22
| ||
| 07:48 | merge trunk check-in: 3edbdbd149 user: dkf tags: c11-functions | |
|
2026-04-21
| ||
| 06:22 | Merge-mark check-in: e5adbad425 user: jan.nijtmans tags: trunk, main | |
|
2026-04-11
| ||
| 21:18 | Match trunk filename capitalisation. check-in: a1f3cdcf0a user: dkf tags: c11-functions | |
| 20:52 | merge trunk check-in: e6af7b1b6f user: dkf tags: c11-functions | |
| 05:52 | Remove outdated information from README check-in: 66b4db0152 user: apnadkarni tags: trunk, main | |
|
2026-01-05
| ||
| 15:24 | merge trunk check-in: 23d9e3f8d8 user: dkf tags: c11-functions | |
| 15:06 | Add divmod as well, to complete the set check-in: af490a1c80 user: dkf tags: c11-functions | |
| 11:47 | Slightly better comments in test file check-in: e6cbfc8183 user: dkf tags: c11-functions | |
|
2026-01-04
| ||
| 21:11 | (cherry-pick) Missing Tcl_WrongNumArgs call check-in: 1c6685fe51 user: jan.nijtmans tags: trunk, main | |
|
2026-01-03
| ||
| 18:31 | Minor testcase fix check-in: 4ff5169432 user: jan.nijtmans tags: c11-functions | |
| 16:01 | merge trunk check-in: 022182d1b5 user: dkf tags: c11-functions | |
| 15:54 | add logb and remquo check-in: 29ffc37c65 user: dkf tags: c11-functions | |
|
2026-01-02
| ||
| 21:44 | Improve arg count tests check-in: b91bab156d user: dkf tags: c11-functions | |
| 15:58 | Add some tests for the new funcs check-in: 7602467f8f user: dkf tags: c11-functions | |
|
2026-01-01
| ||
| 16:15 | Stupid specification stupidity, and rename tgamma to gamma (after reading why the name is what it is... check-in: ddb8bfcde1 user: dkf tags: c11-functions | |
| 15:27 | Added modf as a command check-in: d549d385d4 user: dkf tags: c11-functions | |
| 07:01 | Fix gcc15 warnings - C++ compat, unused vars check-in: a8bfa1d9be user: apnadkarni tags: trunk, main | |
|
2025-12-31
| ||
| 16:03 | Add frexp, as a command because it returns two things really check-in: e5ad1c795f user: dkf tags: c11-functions | |
| 08:48 | More functions check-in: 6eb70b2870 user: dkf tags: c11-functions | |
|
2025-12-30
| ||
| 15:01 | Added trunc() check-in: b28bb6f028 user: dkf tags: c11-functions | |
|
2025-12-29
| ||
| 21:41 | Fix tests check-in: 2633d4bdb4 user: dkf tags: c11-functions | |
| 17:08 | Added documentation for new functions check-in: 1b3ecb342c user: dkf tags: c11-functions | |
| 15:46 | Some more functions check-in: 4d9a8d9cb1 user: dkf tags: c11-functions | |
| 15:23 | More functions from the set available in C11 check-in: a6da976ca2 user: dkf tags: c11-functions | |
|
2025-12-28
| ||
| 16:19 | Fix some indentation of comments check-in: 870237637e user: dkf tags: trunk, main | |