File: constants.man

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (136 lines) | stat: -rw-r--r-- 3,883 bytes parent folder | download | duplicates (2)
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
131
132
133
134
135
136
[comment {-*- tcl -*- doctools manpage}]
[vset VERSION 1.0.2]
[manpage_begin math::constants n [vset VERSION]]
[keywords constants]
[keywords degrees]
[keywords e]
[keywords math]
[keywords pi]
[keywords radians]
[copyright {2004 Arjen Markus <arjenmarkus@users.sourceforge.net>}]
[moddesc   {Tcl Math Library}]
[titledesc {Mathematical and numerical constants}]
[category  Mathematics]
[require Tcl [opt 8.3]]
[require math::constants [opt [vset VERSION]]]

[description]
[para]
This package defines some common mathematical and numerical constants.
By using the package you get consistent values for numbers like pi and
ln(10).

[para]
It defines two commands:

[list_begin itemized]
[item]
One for importing the constants

[item]
One for reporting which constants are defined and what values they
actually have.

[list_end]

[para]
The motivation for this package is that quite often, with
(mathematical) computations, you need a good approximation to, say,
the ratio of degrees to radians. You can, of course, define this
like:
[example {
    variable radtodeg [expr {180.0/(4.0*atan(1.0))}]
}]
and use the variable radtodeg whenever you need the conversion.

[para]
This has two drawbacks:

[list_begin itemized]
[item]
You need to remember the proper formula or value and that is
error-prone.

[item]
Especially with the use of mathematical functions like [emph atan]
you assume that they have been accurately implemented. This is seldom or
never the case and for each platform you can get subtle differences.

[list_end]

Here is the way you can do it with the [emph math::constants] package:
[example {
    package require math::constants
    ::math::constants::constants radtodeg degtorad
}]
which creates two variables, radtodeg and (its reciprocal) degtorad
in the calling namespace.

[para]
Constants that have been defined (their values are mostly taken
from mathematical tables with more precision than usually can be
handled) include:

[list_begin itemized]
[item]
basic constants like pi, e, gamma (Euler's constant)

[item]
derived values like ln(10) and sqrt(2)

[item]
purely numerical values such as 1/3 that are included for convenience
and for the fact that certain seemingly trivial computations like:
[example {
    set value [expr {3.0*$onethird}]
}]
give [emph exactly] the value you expect (if IEEE arithmetic is
available).

[list_end]

The full set of named constants is listed in section [sectref Constants].

[section "PROCEDURES"]

The package defines the following public procedures:

[list_begin definitions]

[call [cmd ::math::constants::constants] [arg args]]

Import the constants whose names are given as arguments

[para]

[call [cmd ::math::constants::print-constants] [arg args]]

Print the constants whose names are given as arguments on the screen
(name, value and description) or, if no arguments are given, print all
defined constants. This is mainly a convenience procedure.

[list_end]

[section "Constants"]
[list_begin definitions]
[def [const pi]]       Ratio of circle circumference to diameter
[def [const e]]	       Base for natural logarithm
[def [const ln10]]     Natural logarithm of 10
[def [const phi]]      Golden ratio
[def [const gamma]]    Euler's constant
[def [const sqrt2]]    Square root of 2
[def [const thirdrt2]] One-third power of 2
[def [const sqrt3]]    Square root of 3
[def [const radtodeg]] Conversion from radians to degrees
[def [const degtorad]] Conversion from degrees to radians
[def [const onethird]] One third (0.3333....)
[def [const twothirds]]Two thirds (0.6666....)
[def [const onesixth]] One sixth (0.1666....)
[def [const huge]]     (Approximately) largest number
[def [const tiny]]     (Approximately) smallest number not equal zero
[def [const eps]]      Smallest number such that 1+eps != 1
[list_end]

[vset CATEGORY {math :: constants}]
[include ../common-text/feedback.inc]
[manpage_end]