Signum: Difference between revisions

Jump to navigation Jump to search
108 bytes added ,  21:32, 10 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
m (Text replacement - "</source>" to "</syntaxhighlight>")
m (Text replacement - "<source" to "<syntaxhighlight")
 
Line 3: Line 3:
== Examples ==
== Examples ==


The three possible results of Signum on a real argument are <source lang=apl inline>0</syntaxhighlight>, <source lang=apl inline>1</syntaxhighlight>, and <source lang=apl inline>¯1</syntaxhighlight>.
The three possible results of Signum on a real argument are <syntaxhighlight lang=apl inline>0</syntaxhighlight>, <syntaxhighlight lang=apl inline>1</syntaxhighlight>, and <syntaxhighlight lang=apl inline>¯1</syntaxhighlight>.
<source lang=apl>
<syntaxhighlight lang=apl>
       × ¯3 0 5
       × ¯3 0 5
¯1 0 1
¯1 0 1
</syntaxhighlight>
</syntaxhighlight>
In dialects with [[complex number]]s, Signum is a somewhat more complicated function, and may return any unit complex number.
In dialects with [[complex number]]s, Signum is a somewhat more complicated function, and may return any unit complex number.
<source lang=apl>
<syntaxhighlight lang=apl>
       × 3j4
       × 3j4
0.6J0.8
0.6J0.8
</syntaxhighlight>
</syntaxhighlight>
The result is still equal to the original number [[divide]]d by its [[magnitude]]:
The result is still equal to the original number [[divide]]d by its [[magnitude]]:
<source lang=apl>
<syntaxhighlight lang=apl>
       | 3j4
       | 3j4
5
5
Line 21: Line 21:
</syntaxhighlight>
</syntaxhighlight>
The [[magnitude]] of the result for a non-zero argument is always 1.
The [[magnitude]] of the result for a non-zero argument is always 1.
<source lang=apl>
<syntaxhighlight lang=apl>
       | × 3j4 ¯2j1 6j¯7
       | × 3j4 ¯2j1 6j¯7
1 1 1
1 1 1
Line 28: Line 28:
== Zero divided by zero ==
== Zero divided by zero ==


The identity <source lang=apl inline>×z</syntaxhighlight> {{←→}} <source lang=apl inline>z÷|z</syntaxhighlight> holds only when <source lang=apl inline>z</syntaxhighlight> is not zero in most APLs. In "Zero Divided by Zero"<ref>[[Eugene McDonnell|McDonnell, Eugene]]. [https://www.jsoftware.com/papers/eem/0div0.htm "Zero Divided by Zero"]. [[APL76]].</ref>, [[Eugene McDonnell]] gave this identity as a reason to define <source lang=apl inline>0÷0</syntaxhighlight> to be equal to <source lang=apl inline>0</syntaxhighlight>. In [[J]], which took McDonnell's suggestion, the identity always holds. [[Dyalog APL]] and [[NARS2000]] allow choosing [[division method]] though the default remains 1.
The identity <syntaxhighlight lang=apl inline>×z</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>z÷|z</syntaxhighlight> holds only when <syntaxhighlight lang=apl inline>z</syntaxhighlight> is not zero in most APLs. In "Zero Divided by Zero"<ref>[[Eugene McDonnell|McDonnell, Eugene]]. [https://www.jsoftware.com/papers/eem/0div0.htm "Zero Divided by Zero"]. [[APL76]].</ref>, [[Eugene McDonnell]] gave this identity as a reason to define <syntaxhighlight lang=apl inline>0÷0</syntaxhighlight> to be equal to <syntaxhighlight lang=apl inline>0</syntaxhighlight>. In [[J]], which took McDonnell's suggestion, the identity always holds. [[Dyalog APL]] and [[NARS2000]] allow choosing [[division method]] though the default remains 1.


== See also ==
== See also ==

Navigation menu