1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
# TIP 745: Functions from C11
This is [TIP #745](tip:745.md). This branch adds more mathematical functions from the set listed [here](https://en.cppreference.com/w/c/numeric/math.html).
# 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 an `f` prefix 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 the `t` prefix.
* **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
|: Name |: Description |: Tcl notes
|: 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
|: Name |: Description |: Tcl notes
|: C Name |: Description |: Tcl notes
------------------------------------------------------------------------------------
| **exp** | computes _e_ raised to the given power (_e_<sup>x</sup>) | Existing: `exp()` function
| **exp2** | computes 2 raised to the given power (2<sup>x</sup>) | _This branch:_ `exp2()` function
| **expm1** | computes _e_ raised to the given power, minus one (_e_<sup>x</sup>-1) | _This branch_
| **log** | computes natural (base-_e_) logarithm (ln(x)) | Existing: `log()` function
| **log10** | computes common (base-10) logarithm (log<sub>10</sub>(x)) | Existing: `log10()` function
| **log2** | computes base-2 logarithm (log<sub>2</sub>(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
|: Name |: Description |: Tcl notes
|: C Name |: Description |: Tcl notes
--------------------------------------------------------------------------------------
| **pow** | computes a number raised to the given power (x<sup>y</sup>) | Existing: `pow()` function and `**` operator
| **sqrt** | computes square root (√x) | Existing: `sqrt()` function
| **cbrt** | computes cube root (<sup>3</sup>√x) | _This branch:_ `cbrt()` function
| **hypot** | computes square root of the sum of the squares of two given numbers (√(x<sup>2</sup>+y<sup>2</sup>)) | Existing: `hypot()` function
## Trigonometric functions
|: Name |: Description |: Tcl notes
|: 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<sup>-1</sup>(x)) | Existing: `asin()` function
| **acos** | computes arc cosine (cos<sup>-1</sup>(x)) | Existing: `acos()` function
| **atan** | computes arc tangent (tan<sup>-1</sup>(x)) | Existing: `atan()` function
| **atan2** | computes arc tangent, using signs to determine quadrants | Existing: `atan2()` function
## Hyperbolic functions
|: Name |: Description |: Tcl notes
|: 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<sup>-1</sup>(x)) | _This branch:_ `asinh()` function
| **acosh** | computes inverse hyperbolic cosine (cosh<sup>-1</sup>(x)) | _This branch:_ `acosh()` function
| **atanh** | computes inverse hyperbolic tangent (tanh<sup>-1</sup>(x)) | _This branch:_ `atanh()` function
## Error and gamma functions
|: Name |: Description |: Tcl notes
|: 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
|: Name |: Description |: Tcl notes
|: 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
|: Name |: Description |: Tcl notes
|: 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
|: Name |: Description |: Tcl notes
|: 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
|