4,494
edits
m (Text replacement - "</source>" to "</syntaxhighlight>") |
m (Text replacement - "<source" to "<syntaxhighlight") Tags: Mobile edit Mobile web edit |
||
Line 1: | Line 1: | ||
A '''complex number''' type is a [[number|numeric type]] which represents, usually with some limited precision, the [[wikipedia:Complex number|complex numbers]]. Complex number support is defined as an optional facility in the XAPL standard ([[ISO/IEC 13751:2001]]), and complex numbers are available in many APLs. Usually these numbers are written with a syntax such as < | A '''complex number''' type is a [[number|numeric type]] which represents, usually with some limited precision, the [[wikipedia:Complex number|complex numbers]]. Complex number support is defined as an optional facility in the XAPL standard ([[ISO/IEC 13751:2001]]), and complex numbers are available in many APLs. Usually these numbers are written with a syntax such as <syntaxhighlight lang=apl inline>5j2</syntaxhighlight> or <syntaxhighlight lang=apl inline>5J2</syntaxhighlight> for the complex number with real part 5 and imaginary part 2. | ||
== Examples == | == Examples == | ||
Complex numbers are usually written with a "J" joining the real and imaginary parts. Complex numbers are added component-wise. | Complex numbers are usually written with a "J" joining the real and imaginary parts. Complex numbers are added component-wise. | ||
< | <syntaxhighlight lang=apl> | ||
1J¯2 + 3J4 | 1J¯2 + 3J4 | ||
4J2 | 4J2 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The [[Circle function]] can be used to split a complex number into its components: a left argument of 9 gets the real part and a left argument of 11 gets the imaginary part. With the [[Rank operator]], Circle can be used to convert a [[shape]] < | The [[Circle function]] can be used to split a complex number into its components: a left argument of 9 gets the real part and a left argument of 11 gets the imaginary part. With the [[Rank operator]], Circle can be used to convert a [[shape]] <syntaxhighlight lang=apl inline>s</syntaxhighlight> complex array to a shape <syntaxhighlight lang=apl inline>s,2</syntaxhighlight> real array where each row contains the components of one complex number. | ||
< | <syntaxhighlight lang=apl> | ||
9 11 ○ 12J3 | 9 11 ○ 12J3 | ||
12 3 | 12 3 | ||
Line 18: | Line 18: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Operations on real numbers can sometimes yield complex numbers. Famously, the square root of minus one is the imaginary unit: | Operations on real numbers can sometimes yield complex numbers. Famously, the square root of minus one is the imaginary unit: | ||
< | <syntaxhighlight lang=apl> | ||
¯1*÷2 | ¯1*÷2 | ||
0J1 | 0J1 |