math::constants(n)
π math::constants(n) π
okay bestie, so this is the manual page for math::constants, which lives in the Tcl Math Library (tcllib, version 1.0.4). it's giving "math class but make it cute". let's go π§
β¨ NAME β¨
math::constants β mathematical and numerical constants, aka the girlies of the number world π
πΈ SYNOPSIS πΈ
package require Tcl ?8.3?
package require math::constants ?1.0.4?
::math::constants::constants args
::math::constants::print-constants args
π¦ DESCRIPTION π¦
so this package defines some common mathematical and numerical constants. by using the package you get consistent values for numbers like pi and ln(10). consistency?? we love her. periodt.
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))}]
and use the variable radtodeg whenever you need the conversion. and like, valid. butβ
this has two drawbacks:
- you need to remember the proper formula or value and that is error-prone π
- especially with the use of mathematical functions like
atanyou assume that they have been accurately implemented. this is seldom or never the case and for each platform you can get subtle differences. not the vibe.
here is the way you can do it with the math::constants package:
package require math::constants
::math::constants::constants radtodeg degtorad
which creates two variables, radtodeg and (its reciprocal) degtorad in the calling namespace. reciprocal?? she's matching energy π
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)andsqrt(2) - purely numerical values such as
1/3that 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). she's precise AND lowkey dramatic about it π
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. just hand her the names, she handles the rest β¨::math::constants::print-constants 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. she's basically your group chat recap π«Ά
π CONSTANTS π
piβ ratio of circle circumference to diametereβ base for natural logarithmln10β natural logarithm of 10phiβ golden ratiogammaβ Euler's constantsqrt2β square root of 2thirdrt2β one-third power of 2sqrt3β square root of 3radtodegβ conversion from radians to degreesdegtoradβ conversion from degrees to radiansonethirdβ one third (0.3333....)twothirdsβ two thirds (0.6666....)onesixthβ one sixth (0.1666....)hugeβ (approximately) largest numbertinyβ (approximately) smallest number not equal zeroepsβ smallest number such that1+eps != 1
π BUGS, IDEAS, FEEDBACK π
this document, and the package it describes, will undoubtedly contain bugs and other problems. (ngl, iconic honesty.) please report such in the category math :: constants of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist.
please also report any ideas for enhancements you may have for either package and/or documentation. we want the glow-up π
when proposing code changes, please provide unified diffs, i.e the output of diff -u.
note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. don't make her scroll, bestie π
π KEYWORDS π
constants, degrees, e, math, pi, radians
π CATEGORY π
Mathematics
π COPYRIGHT π
Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
and that's the whole page!! this bad girl shipped as part of tcllib version 1.0.4, and yeah the footer is literally just tcllib + 1.0.4 + math::constants(n) so like... consider it mentioned, cuties. bye bestie, go compute something gorgeous πβ¨π
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2004 Arjen Markus <arjenmarkus@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms