4,494
edits
m (Text replacement - "http://help.dyalog.com" to "https://help.dyalog.com") Tags: Mobile edit Mobile web edit |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
:''This page describes the monadic arithmetic function. For logical negation of a single argument, see [[Not]]. For dyadic subtraction (minus), see [[Subtract]].'' | :''This page describes the monadic arithmetic function. For logical negation of a single argument, see [[Not]]. For dyadic subtraction (minus), see [[Subtract]]. For the negative sign of a number, see [[High minus]].'' | ||
{{Built-in|Negate|-}}, or '''Minus''', is a [[monadic]] [[scalar function]] which returns the [[wikipedia:additive inverse|additive inverse]] of its argument. It shares a [[glyph]] <source lang=apl inline>-</source> with [[Subtract]], which may also be called Minus, and may be considered a case of Subtract with a default left argument of zero. | {{Built-in|Negate|-}}, or '''Minus''', is a [[monadic]] [[scalar function]] which returns the [[wikipedia:additive inverse|additive inverse]] of its argument. It shares a [[glyph]] <source lang=apl inline>-</source> with [[Subtract]], which may also be called Minus, and may be considered a case of Subtract with a default left argument of zero. | ||
Line 23: | Line 23: | ||
For integers, which are always stored in [[wikipedia:two's complement|two's complement]] format on modern computers, Negate forces a conversion to a higher type when passed the smallest possible value: for example, the range of 1-byte integers is from <source lang=apl inline>¯128</source> to <source lang=apl inline>127</source> inclusive, so <source lang=apl inline>-¯128</source> requires a 2-byte integer to store. Similarly, negating a [[Boolean]] array (that is, 1-bit unsigned values) forces it to be converted to an integer array. These conversions cannot cause a loss of precision in any normal APL because the result is a power of two, and is exactly representable in floating-point format. In [[K]], which wraps on integer overflow, there is also no possibility of such a loss of precision because the minimum 4-byte integer is used as a null value, making the integer range symmetric. | For integers, which are always stored in [[wikipedia:two's complement|two's complement]] format on modern computers, Negate forces a conversion to a higher type when passed the smallest possible value: for example, the range of 1-byte integers is from <source lang=apl inline>¯128</source> to <source lang=apl inline>127</source> inclusive, so <source lang=apl inline>-¯128</source> requires a 2-byte integer to store. Similarly, negating a [[Boolean]] array (that is, 1-bit unsigned values) forces it to be converted to an integer array. These conversions cannot cause a loss of precision in any normal APL because the result is a power of two, and is exactly representable in floating-point format. In [[K]], which wraps on integer overflow, there is also no possibility of such a loss of precision because the minimum 4-byte integer is used as a null value, making the integer range symmetric. | ||
== See also == | |||
* [[Signum]] | |||
* [[Conjugate]] | |||
* [[Reciprocal]] | |||
== External links == | == External links == | ||
Line 28: | Line 33: | ||
=== Documentation === | === Documentation === | ||
* [ | * [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Negative.htm Dyalog] | ||
* [http://microapl.com/apl_help/ch_020_020_030.htm APLX] | * [http://microapl.com/apl_help/ch_020_020_030.htm APLX] | ||
* J [https://www.jsoftware.com/help/dictionary/d120.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/minus NuVoc] | * J [https://www.jsoftware.com/help/dictionary/d120.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/minus NuVoc] | ||
{{APL built-ins}} | {{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar monadic functions]] |