manual:chapter6:operators:cmd_ovr_add

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
manual:chapter6:operators:cmd_ovr_add [2019/10/07 16:03]
jojo1973 Template almost finalized. Next update will be definitive
manual:chapter6:operators:cmd_ovr_add [2019/10/17 14:43]
jojo1973 Finished
Line 1: Line 1:
-==== + ====+==== + (Add) ====
 ---- ----
 <callout type="primary" color="" icon="fa fa-book" title="Synopsis"> <callout type="primary" color="" icon="fa fa-book" title="Synopsis">
Line 9: Line 9:
 ---- ----
 ^  __Input Stack__  ^^  ^  __Output Stack__  ^ ^  __Input Stack__  ^^  ^  __Output Stack__  ^
-|  **O**  |  **O**  |  **→**  |  **O**  |+|  **Num<sub>1</sub>**  |  **Num<sub>2</sub>**  |  **→**  |  **Num<sub>3</sub>** 
 +|  **Num<sub>1</sub>**  |  **Z<sub>2</sub>**  |  **→**  |  **Z<sub>3</sub>** 
 +|  **Num<sub>1</sub>**  |  **∡<sub>2</sub>**  |  **→**  |  **∡<sub>3</sub>** 
 +|  **Num<sub>1</sub>**  |  **A<sub>2</sub>**  |  **→**  |  **'Num<sub>1</sub> + A<sub>2</sub>'** 
 +|  **Z<sub>1</sub>**  |  **Z<sub>2</sub>**  |  **→**  |  **Z<sub>3</sub>** 
 +|  **Z<sub>1</sub>**  |  **Num<sub>2</sub>**  |  **→**  |  **Z<sub>3</sub>** 
 +|  **Z<sub>1</sub>**  |  **∡<sub>2</sub>**  |  **→**  |  **Z<sub>3</sub>** 
 +|  **Z<sub>1</sub>**  |  **A<sub>2</sub>**  |  **→**  |  **'Z<sub>1</sub> + A<sub>2</sub>'** 
 +|  **∡<sub>1</sub>**  |  **∡<sub>2</sub>**  |  **→**  |  **∡<sub>3</sub>** 
 +|  **∡<sub>1</sub>**  |  **Num<sub>2</sub>**  |  **→**  |  **∡<sub>3</sub>** 
 +|  **∡<sub>1</sub>**  |  **Z<sub>2</sub>**  |  **→**  |  **Z<sub>3</sub>** 
 +|  **∡<sub>1</sub>**  |  **A<sub>2</sub>**  |  **→**  |  **'∡<sub>1</sub> + A<sub>2</sub>'** 
 +|  **A<sub>1</sub>**  |  **A<sub>2</sub>**  |  **→**  |  **'A<sub>1</sub> + A<sub>2</sub>'** 
 +|  **A<sub>1</sub>**  |  **Num<sub>2</sub>**  |  **→**  |  **'A<sub>1</sub> + Num<sub>2</sub>'** 
 +|  **A<sub>1</sub>**  |  **Z<sub>2</sub>**  |  **→**  |  **'A<sub>1</sub> + Z<sub>2</sub>'** 
 +|  **A<sub>1</sub>**  |  **U<sub>2</sub>**  |  **→**  |  **'A<sub>1</sub> + U<sub>2</sub>'** 
 +|  **A<sub>1</sub>**  |  **∡<sub>2</sub>**  |  **→**  |  **'A<sub>1</sub> + ∡<sub>2</sub>'** 
 +|  **U<sub>1</sub>**  |  **U<sub>2</sub>**  |  **→**  |  **U<sub>3</sub>** 
 +|  **U<sub>1</sub>**  |  **A<sub>2</sub>**  |  **→**  |  **'U<sub>1</sub> + A<sub>2</sub>'** 
 +|  **M<sub>1</sub>**  |  **M<sub>2</sub>**  |  **→**  |  **M<sub>3</sub>** 
 +|  **V<sub>1</sub>**  |  **V<sub>2</sub>**  |  **→**  |  **V<sub>3</sub>** 
 +|  **S<sub>1</sub>**  |  **S<sub>2</sub>**  |  **→**  |  **"S<sub>1</sub>S<sub>2</sub>"** 
 +|  **S<sub>1</sub>**  |  **O<sub>2</sub>**  |  **→**  |  **"S<sub>1</sub>O<sub>2</sub>"** 
 +|  **O<sub>1</sub>**  |  **S<sub>2</sub>**  |  **→**  |  **"O<sub>1</sub>S<sub>2</sub>"**  |
 |  //Level 2 / Argument 1//  |  //Level 1 / Argument 2//  |  **→**  |  //Level 1//  |  |  //Level 2 / Argument 1//  |  //Level 1 / Argument 2//  |  **→**  |  //Level 1//  | 
  
Line 16: Line 39:
 |**Type**| [[manual:chapter5:basics#operators|Operator]]  || |**Type**| [[manual:chapter5:basics#operators|Operator]]  ||
 |**Parallel list processing**| [[manual:chapter5:listproc#group-6two-arguments-one-result-commands|Group 6]]  ||  |**Parallel list processing**| [[manual:chapter5:listproc#group-6two-arguments-one-result-commands|Group 6]]  || 
-|**Affected by flags**|-20| Underflow exception +|**Affected by flags**| [[manual:appendix:flags#flag-20|-20]] | Underflow exception 
-|:::|-21| Overflow exception +|:::| [[manual:appendix:flags#flag-21|-21]] | Overflow exception 
-|:::|-22| Infinite result exception +|:::| [[manual:appendix:flags#flag-22|-22]] | Infinite result exception 
-|:::|-23| Negative underflow flag  | +|:::| [[manual:appendix:flags#flag-23|-23]] | Negative underflow indicator  | 
-|:::|-24| Positive underflow flag  | +|:::| [[manual:appendix:flags#flag-24|-24]] | Positive underflow indicator  | 
-|:::|-25| Overflow flag  | +|:::| [[manual:appendix:flags#flag-25|-25]] | Overflow indicator  | 
-|:::|-26| Infinite flag  |+|:::| [[manual:appendix:flags#flag-26|-26]] | Infinite result indicator  |
 </callout> </callout>
  
 <callout color="orangered" icon="fa fa-comment" title="Description"> <callout color="orangered" icon="fa fa-comment" title="Description">
-Description+---- 
 +In general if the arguments of the sum have the same type so will do the result. However same data types may have different sub-types; in this case the following coercion rules apply: 
 + 
 +  - the sub-type of the first argument determines the sub-type of the result: e.g. the sum between an hexadecimal and an octal integer will be hexadecimal, the sum between an angle in radians and an angle in degrees will be in radians, and so on; 
 +  - if the imaginary part of the sum between a complex number and a scalar is ''0'' the result will be coerced to real type; 
 +  - if the sum between two binary numbers overflows the [[manual:chapter3:numformat|range of binary sub-type]] the result will be coerced to real type; 
 +  - the sum between two unit objects is possible only if the two are dimensionally coherent; 
 +  - the sum between two matrices is possible only if they have the same dimension; 
 +  - the sum between two vectors is possible only if they have the same dimension. 
 + 
 +If the arguments of the sum have different type the following rules apply: 
 + 
 +  - the sum between an angle and a real number will interpret the real number as an angle given in the [[manual:chapter2:interface|current angle mode]]. The result will be an angle expressed in the system of the first argument (current mode if the first argument is the real number); 
 +  - the sum between a complex and a real number will result in a complex number, except when the imaginary part of the result is ''0'': in this case the result will be coerced to real type; 
 +  - the sum between an angle and a complex number will **convert the angle to a real number expressing the angle in radians**. Subsequently the real number will be added to the complex number according to the rule above; 
 +  - when adding two binary integers the binary wordsize is **NOT** taken into account. Use ''[[manual:chapter6:binary:cmd_badd|BADD]]'' if truncation to wordsize is desired; 
 +  - dimensionless units are coherent with scalars and angles therefore they can be added. 
 + 
 +The sum between two matrices or two vectors is done element by element: for each couple of elements the rules above are applied. 
 + 
 +Occurrence of [[manual:chapter3:numformat|underflow]], [[manual:chapter3:numformat|overflow]] or [[manual:chapter3:infinity|infinite]] result will raise an error if one of the corresponding flags from [[manual:appendix:flags#flag-20|-20]] to [[manual:appendix:flags#flag-22|-22]] is cleared. 
 + 
 +If on the contrary one or more of these flags is set, no error will be raised and the matching indicator flag from [[manual:appendix:flags#flag-23|-23]] to [[manual:appendix:flags#flag-26|-26]] will be set.
 </callout> </callout>
  
Line 32: Line 77:
 ---- ----
 This command is only partially compatible with userRPL. This command is only partially compatible with userRPL.
 +
 +In particular:
 +  * coercion rules give precedence to first argument rather than the second;
 +  * the ''+'' operator **does not** concatenate or extend lists anymore: use ''[[manual:chapter6:lists:cmd_add|ADD]]'' instead.
 </callout> </callout>
  
 <callout type="info" icon="true" title="Usage"> <callout type="info" icon="true" title="Usage">
 ---- ----
-The following program: 
 <code> <code>
-« 123 +2:                         #120o 
-  456 +1:                           #3h 
-  789 +…………………………………………………………………………………… 
-  DROP ++ 
-»+</code> 
 +returns ''#123o''
 +---- 
 +<code> 
 +2:                     (1, ∡60°) 
 +1:                             5 
 +…………………………………………………………………………………… 
 +
 +</code> 
 +returns ''(5.5678., ∡8.9483.°)''
 +---- 
 +<code> 
 +2:                      "Hello " 
 +1:                      "world!" 
 +…………………………………………………………………………………… 
 +
 +</code> 
 +returns ''"Hello world!"''
 +---- 
 +<code> 
 +2:                           1_h 
 +1:                        36_min 
 +…………………………………………………………………………………… 
 +
 +</code> 
 +returns ''1.6_h''
 +---- 
 +<code> 
 +2:                       [ 1 2 ] 
 +1:                       [ 1 0 ] 
 +…………………………………………………………………………………… 
 +
 +</code> 
 +returns ''[ 2 2 ]''
 +---- 
 +<code> 
 +2:                           'X' 
 +1:                           'Y' 
 +…………………………………………………………………………………… 
 ++
 </code> </code>
-leaves ''123'' and ''456'' on the stack +returns ''%%'X+Y'%%''.
 </callout> </callout>
  
  • manual/chapter6/operators/cmd_ovr_add.txt
  • Last modified: 2019/11/02 15:06
  • by jojo1973