manual:chapter3:reals

This is an old revision of the document!

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:

Approximate Numbers Exact Numbers
1. 1
1.007. 1.007
1.007.e-10 1.007e-10

Arithmetic performed on numbers takes into account the operands (exact or approximate) and results are displayed accordingly.

For example,

1 3 /

results in 0.333333. (approximate), whereas

1 2 /

results in 0.5 (exact).

Numbers in different bases can be entered by preceding the value with a # and a trailing letter to indicate the base (b = binary, o = octal, d = decimal, h = hexadecimal; note that the trailing letter is case insensitive).

A quicker method consist in the use of the base cycler: simply start keying the number in the preferred base then press RShold-3 and the number on the edit line will cycle between the different bases.

The base cycler is smart enough to skip those 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 tothe afore-mentioned 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 approximated; 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:

#125o #EEh -

yields -#231o.

Here are more examples of arithmetic operations in bases other than 10:

#1101b #FFh +

yields #100001100b.

256 #FFFFh -

yields -65279.

#355o #11010101b *

yields #142461o.

#7h 2 /

yields 3.5.

#2h 63 ^

yields 9.223372E18.

If there is a need to work with different word sizes newRPL provides a dedicated set of commands: first of all, the word size 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 overflow and hence unexpected results, such as this:

« 7 STWS
120 4 BMUL
»

The result is -32, not 480 as expected with a larger word size.

Command Purpose Example
BADD Add #11001b #100000b BADD
BSUB Subtract #11001b #100000b BSUB
BMUL Multiply #11001b #100000b BMUL
BDIV Divide #11001b #100000b BDIV
BAND Bitwise AND #1101010b #1100010b BAND
BOR Bitwise OR #1101010b #1100010b BOR
BXOR Bitwise XOR #1101010b #1100010b BXOR
• manual/chapter3/reals.1572910684.txt.gz