1`math::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.2?`

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`

`38`

`variable radtodeg [expr {180.0/(4.0*atan(1.0))}]`

39`40`

`and use the variable radtodeg whenever you need the conversion.`

41`42`

`This has two drawbacks:`

43`44`

`· You need to remember the proper formula or value and that is`

45`error-prone.`

46`47`

`· Especially with the use of mathematical functions like atan you`

48`assume that they have been accurately implemented. This is sel‐`

49`dom or never the case and for each platform you can get subtle`

50`differences.`

51`52`

`Here is the way you can do it with the math::constants package:`

53`54`

`55`

`package require math::constants`

56`::math::constants::constants radtodeg degtorad`

57`58`

`which creates two variables, radtodeg and (its reciprocal) degtorad in`

59`the calling namespace.`

60`61`

`Constants that have been defined (their values are mostly taken from`

62`mathematical tables with more precision than usually can be handled)`

63`include:`

64`65`

`· basic constants like pi, e, gamma (Euler's constant)`

66`67`

`· derived values like ln(10) and sqrt(2)`

68`69`

`· purely numerical values such as 1/3 that are included for conve‐`

70`nience and for the fact that certain seemingly trivial computa‐`

71`tions like:`

72`73`

`74`

`set value [expr {3.0*$onethird}]`

75`76`

`77`

`give exactly the value you expect (if IEEE arithmetic is avail‐`

78`able).`

79`80`

`The full set of named constants is listed in section Constants.`

81

## PROCEDURES

83`The package defines the following public procedures:`

84`85`

`::math::constants::constants args`

86`Import the constants whose names are given as arguments`

87`88`

`89`

`::math::constants::print-constants args`

90`Print the constants whose names are given as arguments on the`

91`screen (name, value and description) or, if no arguments are`

92`given, print all defined constants. This is mainly a convenience`

93`procedure.`

94

## CONSTANTS

96`pi Ratio of circle circumference to diameter`

97`98`

`e Base for natural logarithm`

99`100`

`ln10 Natural logarithm of 10`

101`102`

`phi Golden ratio`

103`104`

`gamma Euler's constant`

105`106`

`sqrt2 Square root of 2`

107`108`

`thirdrt2`

109`One-third power of 2`

110`111`

`sqrt3 Square root of 3`

112`113`

`radtodeg`

114`Conversion from radians to degrees`

115`116`

`degtorad`

117`Conversion from degrees to radians`

118`119`

`onethird`

120`One third (0.3333....)`

121`122`

`twothirds`

123`Two thirds (0.6666....)`

124`125`

`onesixth`

126`One sixth (0.1666....)`

127`128`

`huge (Approximately) largest number`

129`130`

`tiny (Approximately) smallest number not equal zero`

131`132`

`eps Smallest number such that 1+eps != 1`

133

## BUGS, IDEAS, FEEDBACK

135`This document, and the package it describes, will undoubtedly contain`

136`bugs and other problems. Please report such in the category math ::`

137`constants of the Tcllib Trackers`

138`[http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas`

139`for enhancements you may have for either package and/or documentation.`

140`141`

`When proposing code changes, please provide unified diffs, i.e the out‐`

142`put of diff -u.`

143`144`

`Note further that attachments are strongly preferred over inlined`

145`patches. Attachments can be made by going to the Edit form of the`

146`ticket immediately after its creation, and then using the left-most`

147`button in the secondary navigation bar.`

148

## KEYWORDS

150`constants, degrees, e, math, pi, radians`

151

## CATEGORY

153`Mathematics`

154

## COPYRIGHT

156`Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>`

157`158`

`159`

`160`

`161`

`tcllib 1.0.2 math::constants(n)`