J has a rich constant description syntax. J's constant notation is a sublanguage in its own right.

Useful examples:

1r3

1/3 exactly (rational number)

rational

1.1r3.3

0.3333... floating point approximation of 1.1/3.3=1/3

floating point

1r7

1/7 another exact representation

rational

1r7p0

0.142857... = floating point approximation of 1/7

floating point

1p1

π

floating point

2r3p1

$${2\over 3} \pi$$

floating point

180p_1

$${180\over\pi}$$ = degrees in radian

floating point

1r180p1

$${\pi\over 180}$$ = radians in degree

floating point

0j2p1

$$2\pi i$$ = exponent coefficient in Fourier transformation

complex

_

$$\infty$$, infinity

floating point

__

$$-\infty$$, negative infinity

floating point

_r1, 1r0

$$\infty$$, extended infinity, compare
   _>10^1000x
0
   1r0>10^1000x
1

extended

2b10101010

$$10101010_2 = AA_{16} = 170$$

integer

16baa

same

integer

1 0 1 0 1 0

list of bits

Not so useful examples:

7e1p_2j3e_2b_9j3x1e8

exercise to the reader

1x0j1p1

If this worked, it would demonstrate Euler's equation (i.e. _1 = ^ 1p1 * 0j1), but it doesn't, because 'x' and 'p' are on the same level of the Constant Heirarchy

Delimited Pseudo Constants

Often it's hard to type in and read large values and in user interface they use thousand delimited syntax, such as 1,234.56. The 0&". monad handles this nicely. Here are a few examples:

   0".'1,000.25'
1000.25
   0".'1,000,123'
1000123
   0j15":0".'3.14159,26535,89793'
3.141592653589793
   0".'1,234 5,678.9'
1234 5678.9
   #:0".'2b1000,1000,1000,1000'
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0

Notes:

           nums =. '1 1.0 1r1 1j0 1p0 1e0 1x0 16b1 1x'
           require 'strings'
           (,. ' is '&,"1)&:>/  <@:>"1  (,: datatype@:".&.>) ' ' cut nums
        1    is boolean
        1.0  is boolean
        1r1  is extended
        1j0  is boolean
        1p0  is boolean
        1e0  is boolean
        1x0  is boolean
        16b1 is boolean
        1x   is extended

   16^16
1.84467e19
   16^16+0x
18446744073709551616

1r1 1x

OK

1j1 1x

Not OK. Probably because J doesn't support extended precision complex numbers (and given the first bullet above, the x forces extended precision, so the intepreter can't default the constant to 1j1 1j0).

16bffff 1x

Not OK. This makes some sense because an 'x' suffix in a based number is ambiguous. The trailing x could mean "convert to extended precision" or it could mean "the digit 'x' in base N" (all digits are valid in all based numbers, see below). But if the numeric lexer were slightly smarter, this could be resolved.

Guides/Constants (last edited 2009-09-08 03:41:37 by RicSherlock)