4,494
edits
(→Documentation: BQN) |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
Line 1: | Line 1: | ||
{{Built-in|Residue|<nowiki>|</nowiki>}}, '''Remainder''', or '''Modulus''' is a [[dyadic]] [[scalar function]] which gives the [[wikipedia:Remainder|remainder]] of [[divide|division]] between two real numbers. It takes the divisor as the left [[argument]], and the dividend as the right argument. Residue shares the [[glyph]] <source lang=apl inline>|</ | {{Built-in|Residue|<nowiki>|</nowiki>}}, '''Remainder''', or '''Modulus''' is a [[dyadic]] [[scalar function]] which gives the [[wikipedia:Remainder|remainder]] of [[divide|division]] between two real numbers. It takes the divisor as the left [[argument]], and the dividend as the right argument. Residue shares the [[glyph]] <source lang=apl inline>|</syntaxhighlight> with the monadic arithmetic function [[Magnitude]]. | ||
== Examples == | == Examples == | ||
Line 8: | Line 8: | ||
3.5|5 10 14 | 3.5|5 10 14 | ||
1.5 3 0 | 1.5 3 0 | ||
</ | </syntaxhighlight> | ||
== Properties == | == Properties == | ||
Line 18: | Line 18: | ||
x≡(y|x)+y×⌊x÷y | x≡(y|x)+y×⌊x÷y | ||
1 | 1 | ||
</ | </syntaxhighlight> | ||
== Caveats == | == Caveats == | ||
Line 26: | Line 26: | ||
For negative arguments, one may decide to return non-negative numbers in all cases or follow the sign of the dividend or the divisor. For complex arguments, the [[floor]] of a complex number is not mathematically defined, so allowing complex arguments does not add much of mathematical value. | For negative arguments, one may decide to return non-negative numbers in all cases or follow the sign of the dividend or the divisor. For complex arguments, the [[floor]] of a complex number is not mathematically defined, so allowing complex arguments does not add much of mathematical value. | ||
Dyalog APL uses the expression <source lang=apl inline>Y-X×⌊Y÷X+0=X</ | Dyalog APL uses the expression <source lang=apl inline>Y-X×⌊Y÷X+0=X</syntaxhighlight> as the definition of <source lang=apl inline>X|Y</syntaxhighlight>, so that the above identity holds for all possible arguments. With this definition, zero X returns Y unchanged, and negative X returns a value between X and 0 (excluding the value X). The result for complex arguments is also defined (since Dyalog APL allows them as the argument to [[Floor]]). | ||
<source lang=apl> | <source lang=apl> | ||
Line 35: | Line 35: | ||
3J4{⍵-⍺×⌊⍵÷⍺+0=⍺}5J12 | 3J4{⍵-⍺×⌊⍵÷⍺+0=⍺}5J12 | ||
3J1 | 3J1 | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
== See also == | == See also == |