manual:chapter3:reals

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:chapter3:reals [2017/06/11 17:02]
smartin created
manual:chapter3:reals [2019/11/04 16:06]
jojo1973 More reformatting
Line 1: Line 1:
-===== Numbers =====+===== Basic numbers =====
  
-A number in newRPL is represented as exact or approximate.  To enter a number as approximate use a trailing dot.  To enter a number as exact omit any trailing dot.  For routine arithmetic this distinction doesn't matter much, but it does come into play when evaluating symbolic expressions.+==== Approximate versus Exact ==== 
 + 
 +A number in **newRPL** is represented as exact or approximate.  To enter a number as approximate use a trailing dot.  To enter a number as exact omit any trailing dot.  For routine arithmetic this distinction doesn't matter much, but it does come into play when evaluating symbolic expressions.
  
 Here are some examples: Here are some examples:
  
-| **Approximate Numbers** | **Exact Numbers** | +Approximate Numbers Exact Numbers ^ 
-| 1. | 1 | +''1.'' ''1'' 
-| 1.007. | 1.007 | +''1.007.'' ''1.007'' 
-| 1.007.e-10 | 1.007e-10 |+''1.007.e-10'' ''1.007e-10'' |
  
 Arithmetic performed on numbers takes into account the operands (exact or approximate) and results are displayed accordingly. Arithmetic performed on numbers takes into account the operands (exact or approximate) and results are displayed accordingly.
  
-For example, ''1 3 /'' results in ''0.333.'' (approximate), whereas ''1 2 /'' results in 0.5 (exact).+For example, <code> 
 +2:                             1 
 +1:                             3 
 +…………………………………………………………………………………… 
 +/ 
 +</code> results in ''0.333333333.'' (approximate), whereas <code> 
 +2:                             1 
 +1:                             2 
 +…………………………………………………………………………………… 
 +/ 
 +</code> results in ''0.5'' (exact)
 + 
 +---- 
 + 
 +==== Numbers in other bases ==== 
 + 
 +Numbers in different bases can be entered by preceding the value with a ''#'' and a trailing a letter to indicate the base (''b'' = binary, ''o'' = octal, ''d'' = decimal, ''h'' = hexadecimal; note that the trailing letter is case insensitive and that even if the ''#d'' syntax for decimal numbers is accepted, they are nevertheless displayed without leading ''#'' and trailing ''d''). 
 + 
 +A quicker method to enter these numbers consists in using the **base cycler**: simply start keying the number in the preferred base then press **RS<sup>hold</sup>-3** and the number on the edit line will cycle between the different bases. 
 + 
 +The base cycler is smart enough to skip bases if the keyed number contains illegal digits. For example, if there's ''123'' on the edit line the base cycler will rotate between ''#123o'', ''#123h'' and ''123'', skipping an illegal ''#123b''
 + 
 +If the number is already on the stack the base cycler will display all four bases in succession, provided the number is integer. 
 + 
 +Another option is the BASE menu (**RS-3**): in its first page the soft key will give access to the aforementioned base cycler and four __non-programmable__ base conversion tools which act on the number on the edit line or the first level of the stack. 
 + 
 +Arithmetic can be done on numbers in different bases with the result displayed as the base of the first argument.  Only integer numbers in the range $-(2^{63}-1)$ to $2^{63}-1$ can be expressed in multiple bases. Numbers can be either exact or approximate; outside this range the base will be automatically switched to decimal. 
 + 
 +In other words, it is assumed that **non base-10 numbers are signed, 64-bits integers**. Of these 64 bits, the least significant 63 bits store the magnitude and the 64th most significant bit stores the sign (''0'' means positive, ''1'' means negative). Negative numbers are stored internally in __two's complement__ but are shown as positive numbers with a leading minus sign. 
 + 
 +For example: <code> 
 +2:                         #125o 
 +1:                          #EEh 
 +…………………………………………………………………………………… 
 +
 +</code> yields ''-#231o''
 + 
 +Here are more examples of arithmetic operations in bases other than 10: 
 + 
 +<code> 
 +2:                        #1101b 
 +1:                          #FFh 
 +…………………………………………………………………………………… 
 +
 +</code> yields ''#100001100b''
 + 
 +<code> 
 +2:                           256 
 +1:                        #FFFFh 
 +…………………………………………………………………………………… 
 +
 +</code> yields ''-65279''
 + 
 +<code> 
 +2:                         #355o 
 +1:                    #11010101b 
 +…………………………………………………………………………………… 
 +
 +</code> yields ''#142461o''
 + 
 +<code> 
 +2:                           #7h 
 +1:                             2 
 +…………………………………………………………………………………… 
 +
 +</code> yields ''3.5''
 + 
 +<code> 
 +2:                           #2h 
 +1:                            63 
 +…………………………………………………………………………………… 
 +
 +</code> yields ''9.223372E18''
 + 
 +==== Setting the word size ==== 
 + 
 +If there is a need to work with different word sizes **newRPL** provides a dedicated set of **bit operations**: these command always honor the selected word size //when returning the result//.
  
----- +The word size can be set using the command ''[[manual:chapter6:binary:cmd_stws|STWS]]'' (STore Word Size).  Valid ranges are 1 to 63 (not including the sign bit).  So, for example, to work with __32-bit signed numbers__, set the word size to ''31''. To view the currently set word size, use ''[[manual:chapter6:binary:cmd_rcws|RCWS]]'' (ReCall Word Size).  /Note that setting too small a word size can lead to overflow and hence unexpected results, such as this:
  
 +<code>
 +« 7 STWS
 +  120 4 BMUL
 +»
 +</code>
  
 +The result is ''-32'', not ''480'' as expected with a larger word size.
  
 +==== Bit operations ====
  
 +^ Command ^ Purpose ^ Example ^
 +| ''[[manual:chapter6:binary:cmd_badd|BADD]]'' | Add | ''#11001b #100000b [[manual:chapter6:binary:cmd_badd|BADD]]'' |
 +| ''[[manual:chapter6:binary:cmd_bsub|BSUB]]'' | Subtract | ''#371o #250 [[manual:chapter6:binary:cmd_bsub|BSUB]]'' |
 +| ''[[manual:chapter6:binary:cmd_bmul|BMUL]]'' | Multiply | ''#1A4h #7h [[manual:chapter6:binary:cmd_bmul|BMUL]]'' |
 +| ''[[manual:chapter6:binary:cmd_bdiv|BDIV]]'' | Divide | ''12 5 [[manual:chapter6:binary:cmd_bdiv|BDIV]]'' |
 +| ''[[manual:chapter6:binary:cmd_bneg|BNEG]]'' | Negate (two's complement) | ''#11001b [[manual:chapter6:binary:cmd_bneg|BNEG]]'' |
 +| ''[[manual:chapter6:binary:cmd_band|BAND]]'' | Bitwise AND | ''#1101010b #1100010b [[manual:chapter6:binary:cmd_band|BAND]]'' |
 +| ''[[manual:chapter6:binary:cmd_bor|BOR]]'' | Bitwise OR | ''#1101010b #1100010b [[manual:chapter6:binary:cmd_bor|BOR]]'' |
 +| ''[[manual:chapter6:binary:cmd_bxor|BXOR]]'' | Bitwise XOR | ''#1101010b #1100010b [[manual:chapter6:binary:cmd_bxor|BXOR]]'' |
 +| ''[[manual:chapter6:binary:cmd_bnot|BNOT]]'' | Bitwise NOT (one's complement) | ''#11001b [[manual:chapter6:binary:cmd_bNOT|BNOT]]'' |
  • manual/chapter3/reals.txt
  • Last modified: 2019/11/06 15:21
  • by jojo1973