math::complexnumbers(3tcl)
๐ math::complexnumbers โ the Tcl Math Library's lil complex-number queen ๐
okay so bestie, this is math::complexnumbers(3tcl) from the Tcl Math Library and it is exactly what it says on the tin: a straightforward complex number package. no cap. let's get into it ๐ฆ
โจ SYNOPSIS โจ
package require Tcl 8.5 9
package require math::complexnumbers ?1.0.3?
::math::complexnumbers::+ z1 z2
::math::complexnumbers::- z1 z2
::math::complexnumbers::* z1 z2
::math::complexnumbers::/ z1 z2
::math::complexnumbers::conj z1
::math::complexnumbers::real z1
::math::complexnumbers::imag z1
::math::complexnumbers::mod z1
::math::complexnumbers::arg z1
::math::complexnumbers::complex real imag
::math::complexnumbers::tostring z1
::math::complexnumbers::exp z1
::math::complexnumbers::sin z1
::math::complexnumbers::cos z1
::math::complexnumbers::tan z1
::math::complexnumbers::log z1
::math::complexnumbers::sqrt z1
::math::complexnumbers::pow z1 z2
๐ธ DESCRIPTION ๐ธ
so the complexnumbers mathematical module gives you a straightforward implementation of complex numbers in pure Tcl. and the philosophy?? it's giving "the user knows they're dealing with complex numbers in an abstract way and wants the highest performance possible within the limitations of an interpreted language." periodt. ๐
so because of that whole vibe, the procedures in this package just assume your arguments are valid (representations of) "complex numbers". and what even is a complex number here? it's a list of two numbers: the real part and the imaginary part. although honestly bestie that's a mere detail โ you should just rely on the complex command to construct a valid number for you. don't be out here hand-rolling them ๐
most of the procedures are your basic arithmetic operations or elementary functions, and then a bunch of others convert to and from different representations:
set z [complex 0 1]
puts "z = [tostring $z]"
puts "z**2 = [* $z $z]
and that would result in:
z = i
z**2 = -1
ate. no crumbs. ๐ฅ
๐ AVAILABLE PROCEDURES ๐
the package implements all or most basic operations and elementary functions. iconic behavior honestly.
๐งฎ The arithmetic operations
::math::complexnumbers::+ z1 z2โ add the two arguments together and hand you back the resulting complex number โจcomplex z1 (in)โ first argument in the summationcomplex z2 (in)โ second argument in the summation
::math::complexnumbers::- z1 z2โ subtract the second argument from the first and return the resulting complex number. and if there's only one argument, you get the opposite of z1 back (i.e.-z1) ๐complex z1 (in)โ first argument in the subtractioncomplex z2 (in)โ second argument in the subtraction (optional)
::math::complexnumbers::* z1 z2โ multiply the two arguments and return the resulting complex number ๐complex z1 (in)โ first argument in the multiplicationcomplex z2 (in)โ second argument in the multiplication
::math::complexnumbers::/ z1 z2โ divide the first argument by the second and return the resulting complex numbercomplex z1 (in)โ first argument (numerator) in the divisioncomplex z2 (in)โ second argument (denominator) in the division
::math::complexnumbers::conj z1โ return the conjugate of the given complex number ๐ฆcomplex z1 (in)โ complex number in question
๐ Conversion/inquiry procedures
::math::complexnumbers::real z1โ return the real part of the given complex numbercomplex z1 (in)โ complex number in question
::math::complexnumbers::imag z1โ return the imaginary part of the given complex numbercomplex z1 (in)โ complex number in question
::math::complexnumbers::mod z1โ return the modulus of the given complex numbercomplex z1 (in)โ complex number in question
::math::complexnumbers::arg z1โ return the argument (that's the "angle" in radians, iykyk) of the given complex numbercomplex z1 (in)โ complex number in question
::math::complexnumbers::complex real imagโ construct the complex number"real + imag*i"and return it ๐float real (in)โ the real part of the new complex numberfloat imag (in)โ the imaginary part of the new complex number
::math::complexnumbers::tostring z1โ convert the complex number to the form"real + imag*i"and return the string ๐float complex (in)โ the complex number to be converted
๐ง Elementary functions
::math::complexnumbers::exp z1โ calculate the exponential for the given complex argument and return the resultcomplex z1 (in)โ the complex argument for the function
::math::complexnumbers::sin z1โ calculate the sine function for the given complex argument and return the resultcomplex z1 (in)โ the complex argument for the function
::math::complexnumbers::cos z1โ calculate the cosine function for the given complex argument and return the resultcomplex z1 (in)โ the complex argument for the function
::math::complexnumbers::tan z1โ calculate the tangent function for the given complex argument and return the resultcomplex z1 (in)โ the complex argument for the function
::math::complexnumbers::log z1โ calculate the (principle value of the) logarithm for the given complex argument and return the resultcomplex z1 (in)โ the complex argument for the function
::math::complexnumbers::sqrt z1โ calculate the (principle value of the) square root for the given complex argument and return the resultcomplex z1 (in)โ the complex argument for the function
::math::complexnumbers::pow z1 z2โ calculate"z1 to the power of z2"and return the result ๐ฅcomplex z1 (in)โ the complex number to be raised to a powercomplex z2 (in)โ the complex power to be used
๐ญ BUGS, IDEAS, FEEDBACK ๐ญ
ngl this document, and the package it describes, will undoubtedly contain bugs and other problems. it's giving "we know, we know." so please report them in the category math :: complexnumbers of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and bestie, if you have any ideas for enhancements for either the package and/or the documentation, send those in too ๐ซถ
when you're proposing code changes, please provide unified diffs, i.e. the output of diff -u. this is not optional, it's the vibe.
also!! note that attachments are strongly preferred over inlined patches. you can attach stuff by going to the Edit form of the ticket right after you create it, and then using the left-most button in the secondary navigation bar. so easy. so iconic. โจ
โญ KEYWORDS โญ
complex numbers, math
๐ CATEGORY ๐
Mathematics
๐ COPYRIGHT ๐
Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
okay that's the whole page bestie, you're officially a complex number girlie now ๐ stay hydrated, keep your imaginary parts valid, and remember: this whole thing came to you from tcllib, version 1.0.3, and it's the math::complexnumbers(3tcl) page. mwah ๐ฆโจ
๐ฆ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 ยท Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 ยท Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 ยท Tcl
- 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