math::complexnumbers(3tcl)

๐Ÿ“ฆ
version 2.0 ยท 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– 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 summation
    • complex 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 subtraction
    • complex 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 multiplication
    • complex z2 (in) โ€” second argument in the multiplication
  • ::math::complexnumbers::/ z1 z2 โ€” divide the first argument by the second and return the resulting complex number
    • complex z1 (in) โ€” first argument (numerator) in the division
    • complex 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 number
    • complex z1 (in) โ€” complex number in question
  • ::math::complexnumbers::imag z1 โ€” return the imaginary part of the given complex number
    • complex z1 (in) โ€” complex number in question
  • ::math::complexnumbers::mod z1 โ€” return the modulus of the given complex number
    • complex z1 (in) โ€” complex number in question
  • ::math::complexnumbers::arg z1 โ€” return the argument (that's the "angle" in radians, iykyk) of the given complex number
    • complex 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 number
    • float 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 result
    • complex z1 (in) โ€” the complex argument for the function
  • ::math::complexnumbers::sin z1 โ€” calculate the sine function for the given complex argument and return the result
    • complex z1 (in) โ€” the complex argument for the function
  • ::math::complexnumbers::cos z1 โ€” calculate the cosine function for the given complex argument and return the result
    • complex z1 (in) โ€” the complex argument for the function
  • ::math::complexnumbers::tan z1 โ€” calculate the tangent function for the given complex argument and return the result
    • complex 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 result
    • complex 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 result
    • complex 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 power
    • complex 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 (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