1math::constants(n)             Tcl Math Library             math::constants(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       math::constants - Mathematical and numerical constants
9

SYNOPSIS

11       package require Tcl  ?8.3?
12
13       package require math::constants  ?1.0.1?
14
15       ::math::constants::constants args
16
17       ::math::constants::print-constants args
18
19_________________________________________________________________
20

DESCRIPTION

22       This  package defines some common mathematical and numerical constants.
23       By using the package you get consistent values for numbers like pi  and
24       ln(10).
25
26       It defines two commands:
27
28       ·      One for importing the constants
29
30       ·      One  for  reporting  which constants are defined and what values
31              they actually have.
32
33       The motivation for this package is that quite often,  with  (mathemati‐
34       cal)  computations, you need a good approximation to, say, the ratio of
35       degrees to radians. You can, of course, define this like:
36
37           variable radtodeg [expr {180.0/(4.0*atan(1.0))}]
38
39       and use the variable radtodeg whenever you need the conversion.
40
41       This has two drawbacks:
42
43       ·      You need to remember the proper formula or  value  and  that  is
44              error-prone.
45
46       ·      Especially  with the use of mathematical functions like atan you
47              assume that they have been accurately implemented. This is  sel‐
48              dom  or  never the case and for each platform you can get subtle
49              differences.  Here is the way you can do it with the  math::con‐
50              stants package:
51
52                  package require math::constants
53                  ::math::constants::constants radtodeg degtorad
54
55              which  creates two variables, radtodeg and (its reciprocal) deg‐
56              torad in the calling namespace.
57
58       Constants that have been defined (their values are  mostly  taken  from
59       mathematical  tables  with  more precision than usually can be handled)
60       include:
61
62       ·      basic constants like pi, e, gamma (Euler's constant)
63
64       ·      derived values like ln(10) and sqrt(2)
65
66       ·      purely numerical values such as 1/3 that are included for conve‐
67              nience  and for the fact that certain seemingly trivial computa‐
68              tions like:
69
70                  set value [expr {3.0*$onethird}]
71
72              give exactly the value you expect (if IEEE arithmetic is  avail‐
73              able).
74

PROCEDURES

76       The package defines the following public procedures:
77
78       ::math::constants::constants args
79              Import the constants whose names are given as arguments
80
81
82       ::math::constants::print-constants args
83              Print  the  constants  whose names are given as arguments on the
84              screen (name, value and description) or,  if  no  arguments  are
85              given, print all defined constants. This is mainly a convenience
86              procedure.
87

KEYWORDS

89       constants, degrees, e, math, pi, radians
90
92       Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
93
94
95
96
97math                                 1.0.1                  math::constants(n)
Impressum