math::constants(n) | Tcl Math Library | math::constants(n) |
math::constants - Mathematical and numerical constants
package require Tcl ?8.3?
package require math::constants ?1.0.1?
::math::constants::constants args
::math::constants::print-constants args
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:
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:
and use the variable radtodeg whenever you need the conversion.
variable radtodeg [expr {180.0/(4.0*atan(1.0))}]
This has two drawbacks:
Here is the way you can do it with the math::constants package:
which creates two variables, radtodeg and (its reciprocal) degtorad in the calling namespace.
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:
give exactly the value you expect (if IEEE arithmetic is available).
set value [expr {3.0*$onethird}]
The package defines the following public procedures:
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 SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation.
constants, degrees, e, math, pi, radians
Mathematics
Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
1.0.1 | math |