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/10/16 09:32]
claudio [Numbers in other bases]
Line 1: Line 1:
-===== Numbers =====+===== Basic numbers =====
  
 +----
 +
 +==== 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. 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.
  
Line 12: Line 15:
 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, ''1 3 /'' results in ''0.333.'' (approximate), whereas ''1 2 /'' results in ''0.5'' (exact).
  
 ----  ---- 
  
 +==== Numbers in other bases ====
 +
 +Numbers in different bases can be entered by preceeding the value with a ''#'' and a trailing letter to indicate the base (''b'' = binary, ''o'' = octal, ''d'' = decimal, ''h'' = hex, note that the trailing letter is case insensitive).  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}$ to $2^{63}-1$ can be expressed in multiple bases.  Outside this range the base will be automatically switched to decimal.
 +
 +Here are example arithmetic operations in bases other than 10:
 +
 +''#1101b #FFh +'' yields ''100001100b''
 +
 +''256 #FFFFh +'' yields ''65,791''
 +
 +''#355o #11010101b x'' yields ''#142461o''
 +
 +''#7h 2 /'' yields ''3.5''
 +
 +''#2h 63 Y^X'' yields ''9.223372E18''
 +
 +----
 +
 +==== Bit operations ====
 +
 +| **Command** | **Function** | **Example** |
 +|BADD|Add|''#11001b #100000b BADD'' yields ''#111001b''|
 +|BSUB|Subtract| ''#11001b #100000b BSUB'' yields ''-#111b'' |
 +|BMUL|Multiply| ''#11001b #100000b BMUL'' yields ''#1100100000b'' |
 +|BDIV|Divide| ''#11001b #100000b BDIV'' yields ''#0b'' |
 +|BAND|Logical AND| ''#1101010b #1100010b BAND'' yields ''#1100010b'' |
 +|BOR|Logical OR| ''#1101010b #1100010b BOR'' yields ''#1101010b'' |
 +|BXOR|Logical XOR| ''#1101010b #1100010b BXOR'' yields ''#1000b'' |
 +
 +Note that ''BMUL'' and ''BDIV'' can be used to left shift and right shift numbers (respectively) when the second operand is a power of 2.
 +
 +----
 +
 +==== Setting the word size ====
 +
 +The word size, applicable to exact numbers in other bases, can be set using the command ''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 ''RCWS'' (ReCall Word Size).  //Note that setting too small a word size can lead to "rolling the register" and hence unexpected results, such as this://
 +
 +<code>
 +7 STWS
 +
 +120 4 BMUL
  
 +-32
 +</code>
  
 +The result is -32, not the result of 480 as expected with a larger word size.
  
 +----
  • manual/chapter3/reals.txt
  • Last modified: 2019/11/06 15:21
  • by jojo1973