DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Calculate Argument

01.17.2007
| 3329 views |
  • submit to reddit
        Calculate the argument of a complex number using math:: class.

#!/usr/bin/tclsh
package require Tcl 8.4
package require math::complexnumbers
package require math::constants
package require math::statistics

# Create Constants
::math::constants::constants radtodeg 
::math::constants::constants pi

# Perform Operations
set z 		[ ::math::complexnumbers::complex -2 12]
set zstring 	[ ::math::complexnumbers::tostring $z]
set comp 	[ ::math::complexnumbers::arg $z ]
set dcomp 	[ expr $comp * $radtodeg]

# Results
puts "::math::complexnumbers::arg returned $comp rad ($dcomp deg) for the complex number $zstring"