Difference between revisions of "System Function DR"

From NARS2000
Jump to navigationJump to search
Line 88: Line 88:
  
 
<apll>
 
<apll>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6402 ⎕dr 'NARS2000'</apll> &mdash; Eight 16-bit characters (=128 bits) convert to two 64-bit integers<apll><br />
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6412 ⎕dr 'NARS2000'</apll> &mdash; Eight 16-bit characters (=128 bits) convert to two 64-bit integers<apll><br />
 
23362775258562638 13511005043687474<br />
 
23362775258562638 13511005043687474<br />
 
</apll>
 
</apll>
Line 97: Line 97:
  
 
<apll>
 
<apll>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⍴⎕←1601 ⎕dr 23362775258562638 13511005043687474<br />
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⍴⎕←1611 ⎕dr 23362775258562638 13511005043687474<br />
 
NARS2000<br />
 
NARS2000<br />
 
8<br />
 
8<br />
Line 105: Line 105:
  
 
<apll>
 
<apll>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6402 ⎕dr 2 64⍴1<br />
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6412 ⎕dr 2 64⍴1<br />
 
1 0 2 64<br />
 
1 0 2 64<br />
 
</apll>
 
</apll>
Line 114: Line 114:
  
 
<apll>
 
<apll>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6402 ⎕dr 2 64⍴1 1<br />
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6412 ⎕dr 2 64⍴1 1<br />
 
&nbsp;¯1<br />
 
&nbsp;¯1<br />
 
&nbsp;¯1<br />
 
&nbsp;¯1<br />
Line 132: Line 132:
 
<apll>
 
<apll>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕dr 'a'<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕dr 'a'<br />
1601<br />
+
1611<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 ⎕dr 'a'<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 ⎕dr 'a'<br />
Character (1601):  16 bits per element<br />
+
Character (1611):  16 bits per element<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 ⎕dr ⍳12<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 ⎕dr ⍳12<br />
Arithmetic Progression Array (6404):  64 bit offset + 64 bit multiplier<br />
+
Arithmetic Progression Array (6414):  64 bit offset + 64 bit multiplier -- PV1<br />
 
</apll>
 
</apll>
 +
 +
<p>Some arrays have properties that may be displayed by this function.  The list of such properties is</p>
 +
 +
    <table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
 +
      <tr>
 +
        <td><apll>PV0</apll></td>
 +
        <td>This array is a Permutation Vector, origin-0</td>
 +
      </tr>
 +
      <tr>
 +
        <td><apll>PV1</apll></td>
 +
        <td>This array is a Permutation Vector, origin-1</td>
 +
      </tr>
 +
      <tr>
 +
        <td><apll>All2s</apll></td>
 +
        <td>This array consists of all <apll>2</apll>s</td>
 +
      </tr>
 +
      <tr>
 +
        <td><apll>FPC</apll><i>nnn</i></td>
 +
        <td>This array is a VFP and all entries are represented in Precision <i>nnn</i></td>
 +
      </tr>
 +
      <tr>
 +
        <td><apll>FPC-Mixed</apll></td>
 +
        <td>This array is a VFP whose entries are represented in two or more different precisions</td>
 +
      </tr>
 +
    </table>
 +
 
   </li>
 
   </li>
  
Line 149: Line 175:
 
3FF199999999999A<br />
 
3FF199999999999A<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr '3fd',13⍴'5'<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr '3fd',13⍴'5'<br />
0.33333333333333331<br />
+
0.3333333333333333<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr ¯∞ ∞<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr ¯∞ ∞<br />
 
FFF0000000000000<br />
 
FFF0000000000000<br />
Line 190: Line 216:
 
<apll>
 
<apll>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕ct←0 ⋄ ⎕pp←99<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕ct←0 ⋄ ⎕pp←99<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6403 ⎕dr ¯64↑1<br />
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6413 ⎕dr ¯64↑1<br />
 
¯0<br />
 
¯0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QNaN←6403 ⎕dr ¯64↑13⍴1</apll> &mdash; A Quiet NaN (Not a Number)<apll><br />
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QNaN←6413 ⎕dr ¯64↑13⍴1</apll> &mdash; A Quiet NaN (Not a Number)<apll><br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr QNaN<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr QNaN<br />
 
FFF8000000000000<br />
 
FFF8000000000000<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QNaN=1 2 3 ∞<br />
+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QNaN=QNaN<br />
1 1 1 1<br />
+
0<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr '000fffffffffffff'</apll> &mdash; The largest positive denormal<apll><br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr '000fffffffffffff'</apll> &mdash; The largest positive denormal<apll><br />
2.2250738585072009E¯308<br />
+
2.225073858507201E¯308<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr '0000000000000001'</apll> &mdash; The smallest positive denormal<apll><br />
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 ⎕dr '0000000000000001'</apll> &mdash; The smallest positive denormal<apll><br />
4.9406564584124654E¯324<br />
+
5E¯324<br />
 
</apll>
 
</apll>

Revision as of 02:41, 31 August 2011

Monadic Function

Z←⎕DR R returns the data representation of R.
R is an arbitrary array.
Z is a numeric scalar which represents the datatype of R.


The datatypes are encoded with a unique index in the low-order two digits, and the bits per element in the remaining digits:

  •  110: Boolean, one bit per element
  • 1611: Character, 16 bits per element
  • 6412: Integer, 64 bits per element
  • 6413: Floating Point, 64 bits per element (double precision)
  • 6414: Arithmetic Progression Array, 64 bits each for the offset and multiplier
  • 3218: Heterogeneous, 32 bits per element (each is a pointer)
  • 6418: Heterogeneous, 64 bits per element (each is a pointer)
  • 3219: Nested, 32 bits per element (each is a pointer)
  • 6419: Nested, 64 bits per element (each is a pointer)
  • 3220: Rational, 16 bytes plus two 4-byte pointers plus size of limbs per element
  • 6420: Rational, 16 bytes plus two 8-byte pointers plus size of limbs per element
  • 3221: Variable-precision Floating Point, 12 bytes plus one 4-byte pointer plus size of limbs per element
  • 6421: Variable-precision Floating Point, 12 bytes plus one 8-byte pointer plus size of limbs per element

For example,

      ⎕DR 1 0 1
110
      ⎕dr ⌈/⍬
6413
      ⎕dr 2 64⍴1
— Note this is really an APA, not Boolean
6414
      ⎕dr 2 64⍴1 1
— This one is Boolean because Reshape produces APAs for integer singleton right arguments only
110


Dyadic Function

Z←L ⎕DR R converts R to the datatype indicated by L.
R is an arbitrary array.
L is an integer scalar or one-element vector datatype (see the table above), or a special value (see below).
Z is R where each of the values are converted to the datatype indicated by L.


If the conversion is from a narrower datatype to a wider datatype, there must be exactly enough columns in the right argument to match a multiple of the size of the wider datatype. For example, when converting from character (16-bit) to integer (64-bit), the last column of the right argument must be a multiple of 4 (= 64/16); otherwise, a LENGTH ERROR is signalled.

      6412 ⎕dr 'NARS2000' — Eight 16-bit characters (=128 bits) convert to two 64-bit integers
23362775258562638 13511005043687474

If the conversion is from a wider datatype to a narrower datatype, the number of values in the result is a multiple of the ratio of the wider datatype to the narrower datatype. For example, when converting from integer (64-bit) to character (16-bit), the last column in the result is the product of last column of the right argument and 4 (= 64/16).

For example,

      ⍴⎕←1611 ⎕dr 23362775258562638 13511005043687474
NARS2000
8

Keep in mind how Arithmetic Progression Arrays are created and represented as they can fool you. For example, you might try the following to convert from Boolean to integer:

      6412 ⎕dr 2 64⍴1
1 0 2 64

However, this doesn't produce the expected result because this particular right argument is an APA, not a Boolean vector. That is, under certain circumstances, the reshape primitive creates an APA. In this case, the APA is an array with an offset of 1, a multiplier of 0 and a shape of 2 64.

On the other hand, this expression

      6412 ⎕dr 2 64⍴1 1
 ¯1
 ¯1

produces the expected result because the right argument is now Boolean.

Special Values

There are several special values you may use as a left argument to ⎕dr:

  • The value 0 displays the datatype of the right argument as a text string so you don't need to remember the datatype numbers.

    For example,

          ⎕dr 'a'
    1611
          0 ⎕dr 'a'
    Character (1611): 16 bits per element
          0 ⎕dr ⍳12
    Arithmetic Progression Array (6414): 64 bit offset + 64 bit multiplier -- PV1

    Some arrays have properties that may be displayed by this function. The list of such properties is

    PV0 This array is a Permutation Vector, origin-0
    PV1 This array is a Permutation Vector, origin-1
    All2s This array consists of all 2s
    FPCnnn This array is a VFP and all entries are represented in Precision nnn
    FPC-Mixed This array is a VFP whose entries are represented in two or more different precisions
  • The value 1 converts between character and floating point. This argument makes it easy to see the representation of floating point numbers in order to help understand precision and other floating point issues.

    For example,

          ⎕pp←99
          1 ⎕dr 1.1
    3FF199999999999A
          1 ⎕dr '3fd',13⍴'5'
    0.3333333333333333
          1 ⎕dr ¯∞ ∞
    FFF0000000000000
    7FF0000000000000
          1 ⎕dr '7fe',13⍴'f'
    — The largest positive number
    1.7976931348623157E308
          1 ⎕dr '001',13⍴'0'
    — The smallest positive number
    2.2250738585072014E¯308
          1 ⎕dr '801',13⍴'0'
    — The largest negative number
    ¯2.2250738585072014E¯308
          1 ⎕dr 'ffe',13⍴'f'
    — The smallest negative number
    ¯1.7976931348623157E308

  • The value 2 converts between character and 64-bit integer. This argument makes it easy to see the representation of integers.

    For example,

          2 ⎕dr ¯1
    FFFFFFFFFFFFFFFF
          2 ⎕dr '7',15⍴'f'
    — The largest positive integer
    9223372036854775807
          2 ⎕dr '8',15⍴'0'
    — The smallest negative integer
    ¯9223372036854775808
          2 ⎕dr 9223372036854775807 ¯9223372036854775808
    7FFFFFFFFFFFFFFF
    8000000000000000

A Word of Caution

This system function allows you to create special numbers we don't support in that no other primitive generates these numbers and the behavior of all other primitives on these numbers is undefined. Examples of such special numbers include Quiet NaNs, Signaling NaNs, Negative Zero, and Denormals. If the system doesn't behave as you expect when using these special numbers, don't be surprised.

For example,

      ⎕ct←0 ⋄ ⎕pp←99
      6413 ⎕dr ¯64↑1
¯0
      QNaN←6413 ⎕dr ¯64↑13⍴1
— A Quiet NaN (Not a Number)
      1 ⎕dr QNaN
FFF8000000000000
      QNaN=QNaN
0
      1 ⎕dr '000fffffffffffff'
— The largest positive denormal
2.225073858507201E¯308
      1 ⎕dr '0000000000000001'
— The smallest positive denormal
5E¯324