SYNOPSIS
package require Tcl ?8.3?package require math::constants ?1.0.2?
::math::constants::constants args
::math::constants::printconstants args
DESCRIPTION
This package defines some common mathematical and numerical constants. By using the package you get consistent values for numbers like pi and ln(10).
It defines two commands:
 One for importing the constants
 One for reporting which constants are defined and what values they actually have.
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:

variable radtodeg [expr {180.0/(4.0*atan(1.0))}]
This has two drawbacks:
 You need to remember the proper formula or value and that is errorprone.
 Especially with the use of mathematical functions like 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.
Here is the way you can do it with the math::constants package:

package require math::constants ::math::constants::constants radtodeg degtorad
Constants that have been defined (their values are mostly taken from mathematical tables with more precision than usually can be handled) include:
 •
 basic constants like pi, e, gamma (Euler's constant)
 •
 derived values like ln(10) and sqrt(2)
 •

purely numerical values such as 1/3 that are included for convenience
and for the fact that certain seemingly trivial computations like:

set value [expr {3.0*$onethird}]

 give exactly the value you expect (if IEEE arithmetic is available).
The full set of named constants is listed in section Constants.
PROCEDURES
The package defines the following public procedures: ::math::constants::constants args

Import the constants whose names are given as arguments
 ::math::constants::printconstants 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.
CONSTANTS
 pi
 Ratio of circle circumference to diameter
 e
 Base for natural logarithm
 ln10
 Natural logarithm of 10
 phi
 Golden ratio
 gamma
 Euler's constant
 sqrt2
 Square root of 2
 thirdrt2
 Onethird power of 2
 sqrt3
 Square root of 3
 radtodeg
 Conversion from radians to degrees
 degtorad
 Conversion from degrees to radians
 onethird
 One third (0.3333....)
 twothirds
 Two thirds (0.6666....)
 onesixth
 One sixth (0.1666....)
 huge
 (Approximately) largest number
 tiny
 (Approximately) smallest number not equal zero
 eps
 Smallest number such that 1+eps != 1
BUGS, IDEAS, FEEDBACK
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category math :: constants of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation.KEYWORDS
constants, degrees, e, math, pi, radiansCATEGORY
MathematicsCOPYRIGHT
Copyright (c) 2004 Arjen Markus <[email protected]>