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.
50
51       Here is the way you can do it with the math::constants package:
52
53           package require math::constants
54           ::math::constants::constants radtodeg degtorad
55
56       which creates two variables, radtodeg and (its reciprocal) degtorad  in
57       the calling namespace.
58
59       Constants  that  have  been defined (their values are mostly taken from
60       mathematical tables with more precision than usually  can  be  handled)
61       include:
62
63       ·      basic constants like pi, e, gamma (Euler's constant)
64
65       ·      derived values like ln(10) and sqrt(2)
66
67       ·      purely numerical values such as 1/3 that are included for conve‐
68              nience and for the fact that certain seemingly trivial  computa‐
69              tions like:
70
71                  set value [expr {3.0*$onethird}]
72
73              give  exactly the value you expect (if IEEE arithmetic is avail‐
74              able).
75

PROCEDURES

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

BUGS, IDEAS, FEEDBACK

90       This  document,  and the package it describes, will undoubtedly contain
91       bugs and other problems.  Please report such in the  category  math  ::
92       constants     of     the    Tcllib    SF    Trackers    [http://source
93       forge.net/tracker/?group_id=12883].  Please also report any  ideas  for
94       enhancements you may have for either package and/or documentation.
95

KEYWORDS

97       constants, degrees, e, math, pi, radians
98
100       Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
101
102
103
104
105math                                 1.0.1                  math::constants(n)
Impressum